tags:

views:

57

answers:

4

how we can destroy the session when we click in the close button in my browser..

A: 

unset($_SESSION) - destroys all session variables.

Bakhtiyor
+1  A: 

You can't in any meaningfull reliable way, that is why we invented session.gc_maxlifetime & garbage collecting.

Wrikken
A: 

If they have javascript enabled, you can watch for the onUnload event and make an ajax call to a php file that unsets the session variable.

Typically the browser will delete session cookies on exit, and there is no need to do it on the server side.

Malfist
+4  A: 

You can't destroy the session directly. The session garbage collection doesn't work like that. However if your session is using cookies you could set the cookie lifetime to 0 which translates to "destroy cookie when the browser closes". You can do this with

session_set_cookie_params(0)

The session is still there, but the client can no longer access it effectively destroying the session.

On a side note this will only work if all instances of the browser close.

Manos Dilaverakis