golem Posted March 13, 2007 Share Posted March 13, 2007 Hi, How can I run a logout script when a user close the browser. This is for a login/registratin system, to change a flag in teh database from "online" to "offline" if user closes the browser without loging out. Thank you. Link to comment https://forums.phpfreaks.com/topic/42434-logout-on-closing-browser/ Share on other sites More sharing options...
idevlabsdotcom Posted March 13, 2007 Share Posted March 13, 2007 possibly javascript. php is server side, and has no idea what is happening on the user's end unless it is sent something. i don't do javascript though, so someone else is going to have to chime in. the only way to do it purely in php would be to save a timestamp when someone logs in, and if their session has been inactive for X number of minutes then flag them as logged out. this script would likely be set up to run every X minutes with cron, and will likely hit your database more times than it is worth. it won't have anything to do with the window closing though. if you're interested in this method, a helpful tutorial can be found over at codewalkers.com: http://codewalkers.com/tutorials/14/1.html Link to comment https://forums.phpfreaks.com/topic/42434-logout-on-closing-browser/#findComment-205853 Share on other sites More sharing options...
golem Posted March 13, 2007 Author Share Posted March 13, 2007 Thanks for your answer. If I understand right, if I have a database of 50000 users, I will have to go through all of them periodicaly and compare current time with timestamp stored in the database from last activity? . Link to comment https://forums.phpfreaks.com/topic/42434-logout-on-closing-browser/#findComment-205856 Share on other sites More sharing options...
idevlabsdotcom Posted March 13, 2007 Share Posted March 13, 2007 no, the script that is running periodically to log people out if they are inactive will only need to check those that are already online. there's no point in trying to log someone off that's already offline. Link to comment https://forums.phpfreaks.com/topic/42434-logout-on-closing-browser/#findComment-205860 Share on other sites More sharing options...
golem Posted March 13, 2007 Author Share Posted March 13, 2007 It will still need to go through all the records to check who is online... will that be heavy on server resources, if lets say I want to check every 1 min? Link to comment https://forums.phpfreaks.com/topic/42434-logout-on-closing-browser/#findComment-205862 Share on other sites More sharing options...
interpim Posted March 13, 2007 Share Posted March 13, 2007 hmmm 50k+ queries every 60 seconds... you think it will get done with the first set before it has to start over from the beginning again? Link to comment https://forums.phpfreaks.com/topic/42434-logout-on-closing-browser/#findComment-205884 Share on other sites More sharing options...
legohead6 Posted March 13, 2007 Share Posted March 13, 2007 if you use sessions it automaticly cancels when browse is closed Link to comment https://forums.phpfreaks.com/topic/42434-logout-on-closing-browser/#findComment-205892 Share on other sites More sharing options...
HoTDaWg Posted March 13, 2007 Share Posted March 13, 2007 well if you really think this is important and you have the time, interest, and resources check out AJAX. Link to comment https://forums.phpfreaks.com/topic/42434-logout-on-closing-browser/#findComment-205909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.