xProteuSx Posted February 1, 2007 Share Posted February 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/36602-solved-online-offline-function/ Share on other sites More sharing options...
.josh Posted February 1, 2007 Share Posted February 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/36602-solved-online-offline-function/#findComment-174348 Share on other sites More sharing options...
JasonLewis Posted February 1, 2007 Share Posted February 1, 2007 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. ) Quote Link to comment https://forums.phpfreaks.com/topic/36602-solved-online-offline-function/#findComment-174354 Share on other sites More sharing options...
xProteuSx Posted February 1, 2007 Author Share Posted February 1, 2007 Thanks very much. I have been racking my brain for a while regarding this one. I'm not too proficient at PHP and MySQL, and I was pretty sure I could not do this using the functions that I am familiar with ... Quote Link to comment https://forums.phpfreaks.com/topic/36602-solved-online-offline-function/#findComment-174355 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.