PHP session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
babajee
Forum Newbie
Posts: 5
Joined: Wed Apr 04, 2007 2:38 am

PHP session

Post by babajee »

when session_destory is executed the user logged out, but if direct window is closed then session _destroy is not excuted.

How can i executre at direct browser closed event.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Closing the browser window doesn't pass a request to the server, so you can't. You may be able to attach an AJAX request to the window.close() event I suppose .. assuming browsers allow a request to be sent after the user has tried to close their browser. Even if they did it wouldn't be very reliable because it'd rely on client side scripting.

You should really need to do this anyway. When a browser is closed down the session cookie is destroyed, so the session id is lost forever (assuming your session expiry time is 0). There shouldn't be any way for another user to carry on with the session by restarting the browser.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

with tabbed browsing, I've noticed that if you close the tab the website is in, it doesn't destroy the session. It sits out there until you close the browser and reopen it. Is there a way to destroy the cookie upon closing of the tab?

Wayne
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

No. Sessions are stored for the duration of the browser session. Again, you might be able to attach an AJAX request (or even just a JS function to kill the cookie) to the window.close() event, which should be called when a user closes a tab, but I haven't tried so I don't know for certain.
Post Reply