ewannnn Posted November 11, 2010 Share Posted November 11, 2010 Hi, I have been working on an application where when the user logs in, the status field in the database isset to 1 (online), and when logging off set to 0 (offline). I was wondering if there is a way, using PHP or otherwise, of accomodating for when the user closes the browser manually? I have been looking at other forums who say that it is possible to set a timer which automatically logs the user off after a set amount of time but I dont know how to actually do this or where to start; will the code go on every page of the site? Thanks in advance for any replies Quote Link to comment https://forums.phpfreaks.com/topic/218383-update-database-on-browser-exit/ Share on other sites More sharing options...
revraz Posted November 11, 2010 Share Posted November 11, 2010 You can run a cron job and set a date/time in the table, the cron job then checks this every so often (5 mins?) and if the time limit has passed, set them to logged off in the table. Quote Link to comment https://forums.phpfreaks.com/topic/218383-update-database-on-browser-exit/#findComment-1133010 Share on other sites More sharing options...
BlueSkyIS Posted November 11, 2010 Share Posted November 11, 2010 i would try to use a custom session handler. when the session dies, update the database. Quote Link to comment https://forums.phpfreaks.com/topic/218383-update-database-on-browser-exit/#findComment-1133062 Share on other sites More sharing options...
ewannnn Posted November 11, 2010 Author Share Posted November 11, 2010 Thanks for the advice thats great do you know of any good tutorials to give me an idea how to do it? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/218383-update-database-on-browser-exit/#findComment-1133105 Share on other sites More sharing options...
Rifts Posted November 11, 2010 Share Posted November 11, 2010 i would try to use a custom session handler. when the session dies, update the database. this sounds like an awesome idea Quote Link to comment https://forums.phpfreaks.com/topic/218383-update-database-on-browser-exit/#findComment-1133209 Share on other sites More sharing options...
revraz Posted November 12, 2010 Share Posted November 12, 2010 Problem is, you don't have a lot of control over when the session dies. The GC is not guarenteed to clean up the old session everytime it runs. The best way to handle this is mark their last activity time, after a time period, this considers them logged out. Quote Link to comment https://forums.phpfreaks.com/topic/218383-update-database-on-browser-exit/#findComment-1133340 Share on other sites More sharing options...
ewannnn Posted November 12, 2010 Author Share Posted November 12, 2010 The best way to handle this is mark their last activity time, after a time period, this considers them logged out. I like the sound of this, have you any idea how i would go about doing it? Do you know if there are any good tutorials I could follow? Thanks very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/218383-update-database-on-browser-exit/#findComment-1133371 Share on other sites More sharing options...
revraz Posted November 12, 2010 Share Posted November 12, 2010 Marking activity time is fairly simple. Each time they access any of your pages, just have a time stamp entered into the database. You can check for activity with a cron job every 5 mins, compare it to see if a certain time frame has elapsed, if so, change the field to logged out. Quote Link to comment https://forums.phpfreaks.com/topic/218383-update-database-on-browser-exit/#findComment-1133375 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.