Skip to content Skip to sidebar Skip to footer

Generate A List Of Online Users?

I'm not awesome enough to write a chat application, and I'm trying to get one to work, and I've recently downloaded one from here, it's pretty good so far, as I've tested it out on

Solution 1:

You could so something like storing a timestamp of the users last action in a database, comparing that timestamp when outputting online users and making sure that it was done at most 1 min ago.

Run on all/vital pages: (Deciding if the last action is outdated, you could also check if it was done for one minute ago to reduce the database-load)

if($user['lastAction'] < time()) {
   //update into database, last action is outdated
}

When calculating the amount of users online and is within the loop of each timestamp

//If the users last action was within a minute, the useris most likely online    
if(($row['lastAction']-time()) >60*60)
       //count useras online

Solution 2:

you could have a cron job [if you have cpanel] running on the server once every 60secs or so, that checks when a user last sent anything via the chat if they have not in the last lets say 5mins then remove their entry from the online users list.

Post a Comment for "Generate A List Of Online Users?"