TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-07-2008, 11:02 PM   #1 (permalink)
The Acquainted
 
buildakicker's Avatar
 
Join Date: Jan 2008
Posts: 119
Thanks: 21
buildakicker is on a distinguished road
Confused Destroy Session on Browser Window Closing

Could I do this and destroy the session on the browser window closing?

PHP Code:
session_set_cookie_params(0); 
Thanks!
__________________
SkiLeases.com
buildakicker is offline  
Reply With Quote
Old 05-08-2008, 06:22 AM   #2 (permalink)
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
sjaq is on a distinguished road
Default

You should use session_destroy()
sjaq is offline  
Reply With Quote
Old 05-08-2008, 05:23 PM   #3 (permalink)
The Acquainted
 
drewbee's Avatar
 
Join Date: May 2008
Posts: 175
Thanks: 9
drewbee is on a distinguished road
Default

If you set a cookie (or session), the session automatically destroys on browser close. By default, the cookie is only meant to stay alive for the life of the browser session (and usually 15 minutes of inactvity).
Send a message via AIM to drewbee
drewbee is offline  
Reply With Quote
Old 05-08-2008, 05:40 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by drewbee View Post
If you set a cookie (or session), the session automatically destroys on browser close. By default, the cookie is only meant to stay alive for the life of the browser session (and usually 15 minutes of inactvity).
While that can be true for cookies (depending on the settings), that is not true for sessions. Sessions are stored on the server, the server has no way of knowing when you close your browser. Sessions are destroyed after a certain amount of time of inactivity.

You cant destroy a session when the browser closes. It requires a server side command to do close a session. Theoretically, you could have javascript make an ajax call to a script when the browser closes. Although I don't know if javascript can do this. While you can destroy the cookies that maintain the session ID's, they can be deliberately bypassed by modifying the cookies.
__________________

Village Idiot is offline  
Reply With Quote
Old 05-08-2008, 06:05 PM   #5 (permalink)
The Acquainted
 
drewbee's Avatar
 
Join Date: May 2008
Posts: 175
Thanks: 9
drewbee is on a distinguished road
Default

A simple rule to follow when dealing with cookies. When a user logs in or logs out, always run session_regenerate_id();

Village, and you are correct. The local session information is simply destroyed after x amount of time of inactivity. The AJAX call can happen, but is way more work then what its worth. The only viable way i could see anything coming close to working with what you described would be to
1) Frame the page, keeping one frame hidden.
2) When the hidden frame experiences the onunload event, pop open a new window of which will run the script to destroy the session.

Just an FYI for if you try it, you cannot make an AJAX call onunload. (IE specific I believe, works in firefox... may have that backwards though). I designed an ajax based chatroom before, and one of the ways of detecting if hte user had logged out was checking firing off an AJAX call onunload. One of the browsers wouldn't let it happen though.
Send a message via AIM to drewbee
drewbee is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:47 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design