Link to home
Start Free TrialLog in
Avatar of danfuniel
danfuniel

asked on

destroy session cookies on windows close

Hey everybody!

I'd like to be able to destroy the session cookies when a user closes the browser window. I have a link to "log out" which works great. If a user clicks on it, no problem. BUT if they close the window without clicking on the link, then the cookies stay with the login info for some time. I don't want to set the expire time to something really short, so they don't have to log in multiple times during one surfing session.

I'm not sure if this can be done directly with PHP or a combination of Javascript & PHP. Does anybody have Javascrip/PHP code that will be AUTOMATICALLY executed when a user closes the window manually by clicking on the "X" in the upper right hand corner of their browser?

i'm running
Apache version : Apache/1.3.31
PHP version : 5.0.1

Thanks a lot!!
daniel
Avatar of humeniuk
humeniuk
Flag of Canada image

How is it configured now?  ie. is there an expiry time on the cookie?  Can you post your code?
in the TAG <BODY> put onUnload().

<BODY onUnload="function()">

Take a look at the folowing link:
http://www.phpbuilder.com/lists/php-windows/2002092/0160.php
Avatar of Roonaan
Isn't it so that when all browser windows are unloaded, the session cookie automatically is destroyed?

You could always do something like
<body onUnload="this.style.backgroundImage='http://www.mylogouturl.com';">

The client won't see anything of this errorous imgcall, because the window is quite quickely unloaded.
Avatar of codefather
codefather

I guess if you don't set any expire time for the cookie, it automatically expires when the browser window is closed.
Maybe...

<BODY onBeforeUnload="window.open('logout.php');">
ASKER CERTIFIED SOLUTION
Avatar of Havin_it
Havin_it

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial