Jump to content

[SOLVED] Online-Offline Function


xProteuSx

Recommended Posts

I am trying to create an Online/Offline function for a membership system.  I have created an extra column in the MySQL table that stores user info, called 'userstatus'.  It is set to '0' if the user is offline, and is set to '1' if the user is online.  When the user logs in his status is set to '1'.  When the user logs out, his status is set back to '0'. 

 

My question is, if the user leaves the site without hitting the "Logout" button, how can my script determine that the user is offline? (meaning has left the site, not that he is not connected to the internet).

 

Thanks.  I cannot figure this one out.

Link to comment
https://forums.phpfreaks.com/topic/36602-solved-online-offline-function/
Share on other sites

The short answer is that you can't.

 

However, you can keep track of the user's activity with a timestamp column that is updated every time a page is accessed/refreshed, and then base your userstatus on the timestamp being no longer than x minutes/seconds or however long you wish.

with timestamps you would just update the user table and set there online status to 0 if there time has expired.

so say the amount you have before they are signed out is 30 minutes.

 

$time = 30;

$timeout = time() - ($time * 60);
mysql_query("UPDATE users SET online='0' WHERE timeout<='{$timeout}'");

 

Then whenever the user keeps refreshing the page or changing page update there timeout to the current time().

 

(i may have got the signs mixed around. :P)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.