Jump to content

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.