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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. 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.