Solved

destroy session cookies on windows close

Posted on 2004-09-16
6
5,318 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
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!

 

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 50 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

729 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