limitphp Posted November 3, 2008 Share Posted November 3, 2008 Is there a way to catch when they close the browser with PHP or if they suddenly lose power or exit the site? Or can this only be done in javascript? I have a site that users login to, but if they don't check the remember me box, I want to delete their cookie with their info on it when they leave the site. I'm not using sessions, I'm using cookies and a table to handle logging in. Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/ Share on other sites More sharing options...
revraz Posted November 3, 2008 Share Posted November 3, 2008 Can't do it with just PHP. Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681480 Share on other sites More sharing options...
kenrbnsn Posted November 3, 2008 Share Posted November 3, 2008 Since PHP runs on the server, doing this is impossible unless you use Ajax to communicate the fact to PHP, but even then it may not work. If the machine they are on loses power, how is the Javascript going to do anything? Ken Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681481 Share on other sites More sharing options...
rhodesa Posted November 3, 2008 Share Posted November 3, 2008 When you set the cookie, just use 0 for the expire time. then the cookie while expire at the end of the session Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681482 Share on other sites More sharing options...
revraz Posted November 3, 2008 Share Posted November 3, 2008 I think he wants it to end when they navigate away also. Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681484 Share on other sites More sharing options...
limitphp Posted November 3, 2008 Author Share Posted November 3, 2008 If the machine they are on loses power, how is the Javascript going to do anything? Ken I see. Good point. What about if they leave the site or close the browser? Is there a way to catch them with javascript and php if they leave the site or close the browser? Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681500 Share on other sites More sharing options...
revraz Posted November 3, 2008 Share Posted November 3, 2008 As stated above, set the time to 0 and it will expire when they close the browser. Can't really do anything about leaving the site though. Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681502 Share on other sites More sharing options...
DarkWater Posted November 3, 2008 Share Posted November 3, 2008 Why do you need to delete their info if they decide to go to a different page? Closing the browser is more reasonable. You can just, as rhodesa said, set the cookie expire time to 0. Leaving the site is a much more complicated thing, and I'm not even sure how it would be accomplished. I could probably think of something after a while, but it's still not the best of ideas. Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681504 Share on other sites More sharing options...
limitphp Posted November 3, 2008 Author Share Posted November 3, 2008 I'm sorry, I see what your saying. Sorry, I had one of those brain malfunctions, when you hear what someone says, but it doesn't get fully processed. I have 2 little toddlers now and my brain seems to work alot slower. That makes perfect sense. So, I just set the cookie time to zero like this: setcookie("nwo",$tempID, 0); Thanks guys. Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681512 Share on other sites More sharing options...
rhodesa Posted November 3, 2008 Share Posted November 3, 2008 yup...or just use SESSIONS instead of cookies Link to comment https://forums.phpfreaks.com/topic/131260-solved-catch-closing-browser-or-power-off-with-php/#findComment-681516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.