CodeIgniter Forums
Get all stored sessions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Get all stored sessions (/showthread.php?tid=64382)



Get all stored sessions - vertisan - 02-15-2016

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?


RE: Get all stored sessions - Narf - 02-15-2016

That all_userdata() doesn't do what you think it does.


RE: Get all stored sessions - vertisan - 02-15-2016

(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 ?


RE: Get all stored sessions - Narf - 02-15-2016

(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.


RE: Get all stored sessions - vertisan - 02-15-2016

(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?


RE: Get all stored sessions - Narf - 02-15-2016

(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.


RE: Get all stored sessions - vertisan - 02-15-2016

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?


RE: Get all stored sessions - Narf - 02-15-2016

Don't do that ... trust me, there are too many things to go in a complete driver.
You only need to extend sess_regenerate().


RE: Get all stored sessions - vertisan - 02-16-2016

(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?


RE: Get all stored sessions - Narf - 02-16-2016

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.