needs_upgrade Posted April 17, 2009 Share Posted April 17, 2009 Hi guys! I store online users in mysql database. My problem is that some users don't use the logout button but directly closes the web browser. As a result, their user IDs are still in the database. I want to catch the event whenever the users closes the browser. Or sometimes the browser crashes. I would like to catch that as well. How can i do that? Thanks so much guys. Link to comment https://forums.phpfreaks.com/topic/154572-solved-how-to-catch-a-close-the-browser-event/ Share on other sites More sharing options...
jackpf Posted April 18, 2009 Share Posted April 18, 2009 window.onunload However, this method is unsecure, as it will not execute if javascript is turned off. In favour of javascript, I'd recommend using some sort of timeout method to conclude whether a user is online or not. Link to comment https://forums.phpfreaks.com/topic/154572-solved-how-to-catch-a-close-the-browser-event/#findComment-812848 Share on other sites More sharing options...
xtopolis Posted April 18, 2009 Share Posted April 18, 2009 while jack has a good suggestion, it cannot be entirely relied upon. You need to have server side checking in place to "log users out" after a certain period of inactivity. Link to comment https://forums.phpfreaks.com/topic/154572-solved-how-to-catch-a-close-the-browser-event/#findComment-812880 Share on other sites More sharing options...
jackpf Posted April 18, 2009 Share Posted April 18, 2009 That's pretty much identical to what I said, but yeah. Link to comment https://forums.phpfreaks.com/topic/154572-solved-how-to-catch-a-close-the-browser-event/#findComment-812886 Share on other sites More sharing options...
xtopolis Posted April 18, 2009 Share Posted April 18, 2009 Apologies, I assumed you were talking about a javascript function since you referenced being in favor of javascript. I was talking about the PHP/ASP/CGI side, and interpreted your statement as continuing with javascript. Link to comment https://forums.phpfreaks.com/topic/154572-solved-how-to-catch-a-close-the-browser-event/#findComment-812893 Share on other sites More sharing options...
jackpf Posted April 18, 2009 Share Posted April 18, 2009 Oh right, no lol. Well...great minds think alike I personally check if users are online on my site by updating a timestamp for that user in the database every page they visit. Then, if their timestamp is older than five minutes, I consider them offline. I've found this to work pretty well, as you can get stats like how many guests online, how many users, how long they've been online for etc. Only problem is it's pretty db intensive. Link to comment https://forums.phpfreaks.com/topic/154572-solved-how-to-catch-a-close-the-browser-event/#findComment-813084 Share on other sites More sharing options...
needs_upgrade Posted April 19, 2009 Author Share Posted April 19, 2009 Thanks a lot jackpf and xtopolis. That window.onunload is what i need. I have already implemented your other suggestion before. But having two filters is better. Thanks so much again. Link to comment https://forums.phpfreaks.com/topic/154572-solved-how-to-catch-a-close-the-browser-event/#findComment-813619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.