-
vertisan
Junior Member
-
Posts: 39
Threads: 25
Joined: Feb 2015
Reputation:
0
02-15-2016, 04:20 AM
(This post was last modified: 02-15-2016, 04:20 AM by vertisan.)
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?
-
Narf
Me
-
Posts: 1,589
Threads: 1
Joined: Oct 2014
Reputation:
121
(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: ess_regenerate() so the user ID is carried over when the session ID changes.
-
vertisan
Junior Member
-
Posts: 39
Threads: 25
Joined: Feb 2015
Reputation:
0
02-15-2016, 01:56 PM
(This post was last modified: 02-15-2016, 02:19 PM by vertisan.)
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?
|