2 Replies - 773 Views - Last Post: 23 January 2010 - 07:55 AM Rate Topic: -----

#1 Chosen13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-January 10

Help detecting Online/Offline users.

Post icon  Posted 22 January 2010 - 08:11 PM

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!

Is This A Good Question/Topic? 0
  • +

Replies To: Help detecting Online/Offline users.

#2 garfinkle  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 87
  • Joined: 08-September 09

Re: Help detecting Online/Offline users.

Posted 22 January 2010 - 08:37 PM

View PostChosen13, 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!


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

Was This Post Helpful? 0
  • +
  • -

#3 justaboy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 27-February 09

Re: Help detecting Online/Offline users.

Posted 23 January 2010 - 07:55 AM

i think this php function might help you :
http://php.net/manua...wn-function.php
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1