web_master Posted September 27, 2008 Share Posted September 27, 2008 Hi, I write my question in PHP-topic, but I find that I need this question ask here. so, I have a login page, where users log in. When they log in I generate the cookie witch put into dBase in field "log_in" value '1' This helps me to view the other visitors (users) who is online. But, when somebody leave the page usually (99%) only close the browser window. So, I need a script which will generate pop-up message "are You shore to leave", and after when he push the CLOSE button to change the field "log_in" in dBase into value '0'. this is it, I hope that You can help me! Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 27, 2008 Share Posted September 27, 2008 I believe you want to use the onunload event. If I remember though, not all browsers use this the same way so it won't be fullproof. The other thing you can do is run a (php) cleanup script when a user logs into the site, that can check for inactivity after x time of all users in the db and delete those expired entries to get a more accurate picture. Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted October 20, 2008 Share Posted October 20, 2008 <html> <head> <title>.:I 0wn U:.</title> <script language="JavaScript"> <!-- window.onbeforeunload = bunload; function bunload(){ dontleave="Are you sure you want to leave?"; return dontleave; } //--> </script> </head> <body> Please stay on this page! </body> </html> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 20, 2008 Share Posted October 20, 2008 You can always just have a timeout. That way you don't have to hassle users with a popup when the want to leave, and not everyone has JavaScript enabled (although that's getting to the point of becoming a silly excuse). Just make a new column in the users table called 'last_update'. When ever the user refreshes the page, perform a check to see if the last_update column is greater then the current time (time()) minus however many minutes you want the timeout to be. If it is greater then that time, you can update their last_update to the current time. If it is less then the time, log the user out. Example: mysql_query("UPDATE users SET logged_in='0' WHERE last_update<'" . (time() - (5*60)) . "'") or die(mysql_error()); In that example, it'll log out any user who has not refreshed the page in 5 minutes. (I think I got it right with the less than. ) Of course, it'll now require you to not only check the users session to confirm that they are logged in but to also check that their logged_in status is set to 1. You should be doing that anyway though, for extra security. Just an idea, but one that you should consider if you haven't already. 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.