Welcome Guest, Not a member yet? Register   Sign In
Using data in the session table
#1

Hey,

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:
Code:
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);
        $this->load->view('public/homepage');
        $this->load->view('public/footer');
    }

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:
Code:
<?php
//DEBUG ONLY
    echo '<hr>';
    echo "<pre>";
    print_r($this->session->all_userdata());
    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?

Thanks!
Reply
#2

Any ideas? I'm sure this is possible....
Reply
#3

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.
Reply
#4

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.
Reply
#5

Thanks! This is perfect, appreciate your help Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB