Jump to content

[SOLVED] Catch Closing Browser or Power Off With PHP


limitphp

Recommended Posts

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.

 

 

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

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?

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.

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.