开发者

session destroy help in php

开发者 https://www.devze.com 2023-01-04 00:22 出处:网络
how we can destroy the session when we click in the cl开发者_Python百科ose button in my browser..You can\'t destroy the session directly. The session garbage collection doesn\'t work like that. Howeve

how we can destroy the session when we click in the cl开发者_Python百科ose button in my browser..


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.


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


unset($_SESSION) - destroys all session variables.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消