Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

destroy session cookies on windows close

Posted on 2004-09-16
6
Medium Priority
?
5,333 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:danfuniel
6 Comments
 
LVL 33

Expert Comment

by:humeniuk
ID: 12079523
How is it configured now?  ie. is there an expiry time on the cookie?  Can you post your code?
0
 
LVL 2

Expert Comment

by:montasirma
ID: 12080104
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
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12082624
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:codefather
ID: 12199480
I guess if you don't set any expire time for the cookie, it automatically expires when the browser window is closed.
0
 
LVL 3

Expert Comment

by:hackman_3vilGuy
ID: 12498611
Maybe...

<BODY onBeforeUnload="window.open('logout.php');">
0
 
LVL 10

Accepted Solution

by:
Havin_it earned 150 total points
ID: 12803666
onUnload and onBeforeUnload only work with IE.

No need to worry though - everything I have read on the subject assures me that PHP cookies, like Javascript ones, are destroyed when the browser closes or switches domains if their 'expires' property is not set.

If in doubt, why not do a test-page and see what happens in your Cookies folder?

In XP/IE6, the folder is at C:\Documents and Settings\yourname\Cookies

In XP/Firefox, cookies are all in one file:
C:\Documents and Settings\yourname\Application Data\Mozilla\Firefox\Profiles\default.1kv\cookies.txt
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question