Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

destroy session cookies on windows close

Posted on 2004-09-16
6
Medium Priority
?
5,326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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.

 

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

Technology Partners: 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!

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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

688 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