Page 1 of 1

How to echo out a list of online users

Posted: Fri Mar 18, 2011 10:07 am
by aIexi
Hello,

I'm wondering how I should go about echoing out a list of users who have clicked ANY link within the past 3 minutes? I know that you can either do it with a TIMESTAMP, or with sessions?

I'm wondering which method would be the most effective, and how exactly said method would work?


Thanks,

Alexi

Re: How to echo out a list of online users

Posted: Fri Mar 18, 2011 12:01 pm
by miki
view this function in php manual

Code: Select all

session_set_save_handler

Re: How to echo out a list of online users

Posted: Fri Mar 18, 2011 1:13 pm
by Jonah Bron
It can't be done with sessions. You need to add a column to your users table called "last_visit" or something like that, and store the current time in it whenever a user loads a page. To get the list of current users, just select all users who's last_visit is more recent than a given threshold (say, 2 minutes).

If you have a particularly large users table and/or a lot of traffic, you should instead keep a list of online users in a separate table.

Re: How to echo out a list of online users

Posted: Fri Mar 18, 2011 7:47 pm
by aIexi
Thanks Johan, I'll do that :)

Alexi