PHP 销毁整个会话
示例
如果您有一个想要取消的会话,则可以使用session_destroy()
/*
Let us assume that our session looks like this:
Array([firstname] => Jon, [id] => 123)
We first need to start our session:
*/
session_start();
/*
We can now remove all the values from the `SESSION` superglobal:
If you omitted this step all of the global variables stored in the
superglobal would still exist even though the session had been destroyed.
*/
$_SESSION = array();
//如果需要终止会话,请同时删除会话cookie。
//注意:这将破坏会话,而不仅仅是会话数据!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
//最后,我们可以销毁会话:
session_destroy();使用session_destroy()与使用类似的东西不同,后者会删除存储在超全局变量中的所有值,但不会破坏会话的实际存储版本。$_SESSION=array();SESSION
注意:我们使用而不是因为手册规定:$_SESSION=array();session_unset()
仅session_unset()用于不使用$_SESSION的旧版本代码。
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志