My website is http://www.stickmin.com/ (Please Register!)
I have it so when a user Logs In it updates their status to "Online" and if a user clicks Logout it updates their status to "Offline"...
The problem I have is that some users just click the exit button on their browser and their status doesn't get updated. I need a script to make users logout when they exit... thanks!
Help detecting Online/Offline users.
Page 1 of 12 Replies - 599 Views - Last Post: 23 January 2010 - 07:55 AM
Replies To: Help detecting Online/Offline users.
#2
Re: Help detecting Online/Offline users.
Posted 22 January 2010 - 08:37 PM
Chosen13, on 22 Jan, 2010 - 07:11 PM, said:
My website is http://www.stickmin.com/ (Please Register!)
I have it so when a user Logs In it updates their status to "Online" and if a user clicks Logout it updates their status to "Offline"...
The problem I have is that some users just click the exit button on their browser and their status doesn't get updated. I need a script to make users logout when they exit... thanks!
I have it so when a user Logs In it updates their status to "Online" and if a user clicks Logout it updates their status to "Offline"...
The problem I have is that some users just click the exit button on their browser and their status doesn't get updated. I need a script to make users logout when they exit... thanks!
One way to do it is to set a Session ID entry in the user record when they login using session_id(). Then run a cron script on your server that calls a php file that does something along the lines of
$query = mysql_query("SELECT user_id, session_id FROM users where session_id NOT NULL");
while($row = mysql_fetch_assoc($query))
{
if(!session_id($row['session_id']))
{
query("UPDATE users SET session_id = NULL WHERE user_id = " . $row['user_id']);
}
}
When a user logs out the session is destoryed, therefore session_id($row['session_id'] will return false, if a user closes the browser, the session is destroyed. Again this will return false. Now all you need to do is get your users logged in script to return the list of users where session_id is not set to NULL.
Hope this helps
This post has been edited by garfinkle: 22 January 2010 - 08:38 PM
#3
Re: Help detecting Online/Offline users.
Posted 23 January 2010 - 07:55 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|