Welcome Guest, Not a member yet? Register   Sign In
How to get/display all logged in users?
#1

[eluser]Madmartigan1[/eluser]
I want to show which users are logged in, and guests browsing the site - just like you'd see in phpBB. I am using CI database sessions along with my own auth system.

My question is how?

The first thing I can think of is to update MY auth table with the user's current ip_address on login, and then join on column ip_address to the CI session table.

Or, unserialize all the session userdata (from the session database) and get the user token (which is just an id if logged in, empty if not).

These both seem crappy.

Any better suggestions?
#2

[eluser]Madmartigan1[/eluser]
No bites? Surely somebody has done this!
#3

[eluser]Boris Strahija[/eluser]
Why not add a field to your 'users' table, called something like 'last_action_at' with a timestamp of the last user action on the site. Update the this field on every page for all logged in users, and then just pull, let's say, all users with actions in the last 30 minutes or so.
#4

[eluser]Madmartigan1[/eluser]
Ha! That's perfect.

The problem I couldn't wrap my head around was updating the table on logout, as this may never happen if the user doesn't manually log out.

30 minutes or so seems reasonable.

I've been staring at the computer for too long, I can't believe I didn't think of it, thanks! Smile
#5

[eluser]m4ikel[/eluser]
Quote:The problem I couldn’t wrap my head around was updating the table on logout, as this may never happen if the user doesn’t manually log out.

Solution to that is to simply check which timestamps are older then lets say 30 minutes and delete it from the database. You can check for this everytime someone logs in/out, that way its automated "cron" without any fency crons/scripting.

Google for: timestamp Calculating age

Also check http://ellislab.com/codeigniter/user-gui...sions.html




Theme © iAndrew 2016 - Forum software by © MyBB