日期:2014-05-17  浏览次数:20546 次

关于COOKIE的小问题
php code:
setcookie('loginid',$loginid);
setcookie('islogin',1);

像上面一样,我设置cookie时没有设置生命周期,我想在关掉网页后cookie自动清除掉,该怎么做?

------解决方案--------------------
没有设置生命周期,则浏览器不会保存 cookie ,因此下次进入是没有 cookie 的
不过你需要注意的是“关闭浏览器”而不是“关闭选项卡”
------解决方案--------------------
楼主的代码 可以实现关闭浏览器cookie 就失效的!!
但一定要注意是关闭浏览器,而不是是“选项卡”,我在测试IE8的时候需要把所有的浏览器都关掉cookie才会失效。

php帮助文档原文:
bool setcookie ( string $name [, string $value [, int $expire = 0 ]...]] )
...
$expire :
If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).