php manage online offline users
Moderator: General Moderators
php manage online offline users
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. 
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: php manage online offline users
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'.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: php manage online offline users
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.
This of course only counts if the user has initiated a session at some point.
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;