简体   繁体   English

为什么此setcookie不起作用?

[英]Why this setcookie doesn't work?

setcookie("cookie1", "", 0, "/",".domain.com");
setcookie("cookie2", "", 0, "/",".domain.com");
header('Location: /index.php');

It doesn't delete cookie1 and cookie2. 它不会删除cookie1和cookie2。 Why is that? 这是为什么?

An expiration time of 0 is a special value which means the cookie will be deleted when the browser is closed. 到期时间0是一个特殊值,这意味着Cookie将在关闭浏览器时被删除。 To delete it immediately, you need to give a valid expiration time in the past. 要立即将其删除,您需要指定一个有效的过去时间。 An example from the PHP docs : PHP文档中的一个示例:

// set the expiration date to one hour ago
setcookie ("TestCookie", "", time() - 3600);

My best guess would be that the browser simply hasn't done it yet. 我最好的猜测是浏览器还没有完成。 Cookie management is the responsibility of the browser, and depending on the browser settings it may not delete your cookie immediately. Cookie管理是浏览器的责任,根据浏览器的设置,它可能不会立即删除您的Cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM