小菜鸟再认识session_destroy()

来源:互联网 发布:mac excel 提取数据 编辑:程序博客网 时间:2024/05/20 06:52

/** 燕十八 公益PHP培训

 课堂地址:YY频道88354001

 学习社区:www.zixue.it **/

前几天在做一个用户退出功能时出现了一点小问题,session中的信息不能第一时间删除,直接上代码

<?php
//logout.phpdefine('PASS',true);require_once './include/init.php';unset($_SESSION);session_destroy();$msg='用户退出成功';include ROOT.'view/front/msg.html';?>

第一次刷新时,session中的信息还是会存在的,第二次刷新才会session中的信息就 没了,后来百度,谷歌,查手册发现原来....

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called. 

这段话将的一个核心意思就是session_destroy不能删除客户端保存的关于session的变量,和$_SESSION中的变量,它只是关闭或者毁坏了session的连接。

所以,想要清楚session的变量,可以用unset或者讲变量设为空值

改成下面之后,一运行logout.php页面session中的信息就会被删除了

<?phpdefine('PASS',true);require_once './include/init.php';unset($_SESSION);$msg='用户退出成功';include ROOT.'view/front/msg.html';?>