schme16 Posted November 6, 2006 Share Posted November 6, 2006 I've made a website (http://josef-stalin.com but its not about him dont worry) and i've set it so that when a user logs in it sets a value in the users table data to "online" and for a list of people with this value to be shown on the site.My Question is, how can i make my website set that value to "offline" when the user closes the browser or navigates away from my domain.... or if its easier, how can i set it so that after about 30mins the cookie timesout (but i'd need to be told how to make this way set the value to offline when the cookies has timed out)any help is greatly appreciated! Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2006 Share Posted November 6, 2006 The easiest way is to have a timestamp in this table that gets updated evrytime the user hits a page. You then need to run a cron job every minute or whatever to check to see how old the timestamp is. If its oler than say 5 mins, you could set the user as offline. Quote Link to comment Share on other sites More sharing options...
schme16 Posted November 9, 2006 Author Share Posted November 9, 2006 being a windows user, how do i accomplish the cron job with scheduled tasks? Quote Link to comment Share on other sites More sharing options...
schme16 Posted November 13, 2006 Author Share Posted November 13, 2006 Thanks for the conceptual base upon which i wrote the code (I'm a person that has to understand the process in order to create it...come people can create without knowing that...but often I can write exceptionally when I have thought out what it is being done)...The code I ended up using (for anyone else out there who needs help) is:[code]if (($logged[username]) != (NULL)){$update = mysql_query("Update users set timestamp = '$realtime' where username = '$logged[username]'");}//This strips the user of their online status if the've been 'offline' for x minutes.$getuser = mysql_query("SELECT * from users");while ($user = mysql_fetch_array($getuser)){$sumtime =(($realtime) - ($user[timestamp]));if ($sumtime > 300){$update = mysql_query("Update users set online = 'false' where username = '$user[username]'");}}//this is for the offlinners to get re-instated as online.$getuser = mysql_query("SELECT * from users");while ($user = mysql_fetch_array($getuser)){$sumtime =(($realtime) - ($user[timestamp]));if (($sumtime < 300) and ($user[loggedout] == 'false')){$update = mysql_query("Update users set online = 'true' where username = '$user[username]'");}}[/code]Variable List:$realtime = time();$logged is the persistence of the users settings(table values) Quote Link to comment 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.