CodeIgniter Forums

Full Version: Using data in the session table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

So I'm hoping you can help.

I'd like to list out some data for all users, that is currently set within their user session.

I have my CI3 set to use the database driver for session and essentially in each function of my controller I am setting the page they calling / visiting.

An example would be as follows:
function index()
        $meta['title']    = 'title';
        $meta['tagline']    = 'tagline';
        $this->session->set_userdata('page', 'front page'); // set current page in session data
        $this->load->view('public/header', $meta);

As this is set for every user, logged in or not, what I'd like to do is have a page within my dashboard in which I can view all page entries within the session table.

Basically allowing me to see what page a user is on at any given time.

I can dump this data as follows:
    echo '<hr>';
    echo "<pre>";
    echo "</pre>";


However this is returning everything for a SINGLE user. Me.

I'd like to call parts of the stored session data, but for all users.

Ideally I'd like username, userid and page.

Can anyone point me in the right direction please?

Any ideas? I'm sure this is possible....
There is no method on session library that returns all existent sessions, if you are using database, you must code a model that retrieves all rows on sessions table and unserialize the data field.

I recommend build a tracking model/library instead dig into session stored data, maybe calling a method on a hook or top of a MY_Controller, associating the session_id with and id field, also check time to ignore/clean expired records.
Generally, I would put the data I want into a separate table and use a foreign key to reference the session table. Session data is not really intended to be available to other users on the site. The only significant problem I see with maintaining the separate table is that you would probably want to periodically purge data which is no longer relevant.
Thanks! This is perfect, appreciate your help Smile