How to echo out a list of online users

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aIexi
Forum Newbie
Posts: 12
Joined: Wed Mar 16, 2011 10:46 pm

How to echo out a list of online users

Post 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
miki
Forum Newbie
Posts: 7
Joined: Fri Mar 18, 2011 2:32 am

Re: How to echo out a list of online users

Post by miki »

view this function in php manual

Code: Select all

session_set_save_handler
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: How to echo out a list of online users

Post 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.
aIexi
Forum Newbie
Posts: 12
Joined: Wed Mar 16, 2011 10:46 pm

Re: How to echo out a list of online users

Post by aIexi »

Thanks Johan, I'll do that :)

Alexi
Post Reply