关于COOKIE的小疑点

WBOY
Release: 2016-06-13 10:56:54
Original
925 people have browsed it

关于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). 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!