Welcome Guest, Not a member yet? Register   Sign In
Get all stored sessions
#1

(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?
Reply
#2

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

(This post was last modified: 02-15-2016, 07:09 AM by vertisan.)

(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 ?
Reply
#4

(This post was last modified: 02-15-2016, 08:09 AM by Narf.)

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

(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?
Reply
#6

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

(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?
Reply
#8

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

(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?
Reply
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB