Page 1 of 1
php manage online offline users
Posted: Sat Aug 14, 2010 12:42 pm
by bhagirath
how to manage online users and show list of Online users to each online user and make each online user to offline even if he/she close browser or direct navigate by changing URL address without clicking on sign out or log out link.

Re: php manage online offline users
Posted: Sat Aug 14, 2010 5:56 pm
by Jonah Bron
There really is no surefire way of doing that. The best way is to use a timeout system. In the 'users' table, add a column that contains the timestamp of the last time they visited. If the timestamp is recent enough, list them as 'online'.
Re: php manage online offline users
Posted: Sat Aug 14, 2010 7:34 pm
by John Cartwright
I haven't tested this in a very long time, but the following is used to count temporary session files in PHP's temp dir.
Code: Select all
define('TIMEOUT', 3 * 60); //seconds old until temporary file is no longer counted
$results = glob(session_save_path() . DIRECTORY_SEPARATOR .'sess_*');
$online = 0;
foreach ($results as $session) {
if(time()- fileatime($session) < TIMEOUT) {
$online++;
}
}
echo $online;
This of course only counts if the user has initiated a session at some point.