Welcome Guest, Not a member yet? Register   Sign In
get all logged in user's id
#1

[eluser]aryan_[/eluser]
I'm using table for session. I have a custom session data 'user_id'. Here's sample of 'user_data' column-

a:2:{s:9:"logged_in";s:1:"1";s:7:"user_id";s:1:"1";}

How can I get 'user_id' of all logged in users?

Thanks
#2

[eluser]davidbehler[/eluser]
You would have to select all session entries with activity in the past few minutes, then unserialize the user_data column and get the user_id.

Would be easier if you would had a user_id field in the session table (that field would of course be empty if the user is not logged in), but what can you do Wink
#3

[eluser]aryan_[/eluser]
[quote author="waldmeister" date="1262646698"]You would have to select all session entries with activity in the past few minutes, then unserialize the user_data column and get the user_id.

Would be easier if you would had a user_id field in the session table (that field would of course be empty if the user is not logged in), but what can you do Wink[/quote]

Can you help me with sql query?
#4

[eluser]Sbioko[/eluser]
You can do it with php, not mysql. Use unserialize php function. It converts your string to an array.
#5

[eluser]davidbehler[/eluser]
Code:
$this->db->from('sessions');
$this->db->where('last_activity >= ', 'DATE_ADD(NOW(), -5, MINUTES)', FALSE);
$result = $this->db->get();
I don't know what your columns are called exactly or what type of field they are, this is for type datetime. If you are using timestamp, you would have to get use this:
Code:
$this->db->where('last_actitiy >= ', '(UNIX_TIMESTAMP() - 300)', FALSE);
instead.

That should return all sessions that were used since the last 5 minutes. Now you have to loop over all return rows and check if user_data is not empty and user_id is set and valid.

Hope that helps.
#6

[eluser]aryan_[/eluser]
[quote author="Demedes" date="1262651661"]You can do it with php, not mysql. Use unserialize php function. It converts your string to an array.[/quote]

Wow! Thanks a lot.
#7

[eluser]Sbioko[/eluser]
Not at all:-) Good luck! Have some questions? Ask me!




Theme © iAndrew 2016 - Forum software by © MyBB