CodeIgniter Forums

Full Version: Get all stored sessions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!

I want to create list of logged users.
I set to store sessions in DB and I tried to use
PHP Code:
$this->session->all_userdata(); 
but I getting only data for logged account (ex. when I'm on admin, I getting only data for admin)

Where is the problem?
That all_userdata() doesn't do what you think it does.
(02-15-2016, 05:49 AM)Narf Wrote: [ -> ]That all_userdata() doesn't do what you think it does.

So how can i do this? Normally foreach table from DB? If yes, so how can I get data from 'BLOB' column ?
(02-15-2016, 06:45 AM)vertisan Wrote: [ -> ]
(02-15-2016, 05:49 AM)Narf Wrote: [ -> ]That all_userdata() doesn't do what you think it does.

So how can i do this? Normally foreach table from DB? If yes, so how can I get data from 'BLOB' column ?

You can't reliably read the "blob column" and you really shouldn't.

You need to otherwise map session IDs against user IDs, without trying to read the session data itself. There's no concrete answer to the "how to do this?" question - you can do it in many ways, none of which is easily explainable.
(02-15-2016, 08:09 AM)Narf Wrote: [ -> ]
(02-15-2016, 06:45 AM)vertisan Wrote: [ -> ]
(02-15-2016, 05:49 AM)Narf Wrote: [ -> ]That all_userdata() doesn't do what you think it does.

So how can i do this? Normally foreach table from DB? If yes, so how can I get data from 'BLOB' column ?

You can't reliably read the "blob column" and you really shouldn't.

You need to otherwise map session IDs against user IDs, without trying to read the session data itself. There's no concrete answer to the "how to do this?" question - you can do it in many ways, none of which is easily explainable.

So whether it's a good idea to create another array, ex. 'Logged_users' and each login/logout respectively add/remove a record from the data it needs?
(02-15-2016, 09:33 AM)vertisan Wrote: [ -> ]
(02-15-2016, 08:09 AM)Narf Wrote: [ -> ]
(02-15-2016, 06:45 AM)vertisan Wrote: [ -> ]
(02-15-2016, 05:49 AM)Narf Wrote: [ -> ]That all_userdata() doesn't do what you think it does.

So how can i do this? Normally foreach table from DB? If yes, so how can I get data from 'BLOB' column ?

You can't reliably read the "blob column" and you really shouldn't.

You need to otherwise map session IDs against user IDs, without trying to read the session data itself. There's no concrete answer to the "how to do this?" question - you can do it in many ways, none of which is easily explainable.

So whether it's a good idea to create another array, ex. 'Logged_users' and each login/logout respectively add/remove a record from the data it needs?

Something like that could work, but you're missing one detail - counting the auto-logouts when sessions expire.

Instead, you could add a field for the user ID in the sessions table and update it on login. However, you'd have to also extend CI_Session:Confusedess_regenerate() so the user ID is carried over when the session ID changes.
I do something like this:
Code from model (I using IonAuth):

$this->db->insert( 'ci_sessions', array( 'logged_id' => $user->id ) );
$this->session->set_userdata($session_data);


but now, when I'm logged it's adding 'user_id' to new column - ok, but other are empty, why? (sorry, I'm not good with sessions)


I created 'Session_dummy_driver' with this method:
PHP Code:
public function write($session_id$session_data)
        {
                
$this->db->where'id'$session_id );
                
$this->update'logged_id'$session_data->user_id );
        } 

But not updated 'logged_id' - where is my bad?
Don't do that ... trust me, there are too many things to go in a complete driver.
You only need to extend sess_regenerate().
(02-15-2016, 03:44 PM)Narf Wrote: [ -> ]Don't do that ... trust me, there are too many things to go in a complete driver.
You only need to extend sess_regenerate().

Ok, but ... How do this? I need to edit core method? Or how?
No ... you just need to create a MY_Session extension.
If you don't know how to do that by now, I'd rather discurage you from trying to modify sessions' logic - it's rather complicated and you need to know what you're doing.