[英]Proper expire value to delete a cookie
Per http://php.net/manual/en/function.setcookie.php , they provide the following example to delete a cookie: 对于http://php.net/manual/en/function.setcookie.php ,他们提供了以下示例来删除Cookie:
setcookie ("TestCookie", "", time() - 3600);
Selected answer to Remove a cookie recommends the following: 选定的删除Cookie的答案建议如下:
setcookie('Hello', null, -1, '/');
Should it be time()-3600
, -1
, or something else? 应该是time()-3600
, -1
还是其他?
On a side note, is a value of null
or ""
preferred? 附带说明一下,是否首选null
或""
值?
Try this 尝试这个
if (isset($_COOKIE['TestCookie']))
{
// removing the cookie
unset($_COOKIE['TestCookie']);
// resetting the cookie
setcookie('TestCookie', null, -1, '/');
return true;
} else {
return false;
}
Since cookie expiration time will be checked against clients clock, the best option is: 由于将根据客户端时钟检查Cookie到期时间,因此最佳选择是:
setcookie('Hello', null, 1, '/');
Then you can make sure it will expire instantly. 然后,您可以确保它会立即过期。
Except if the clock is 00:00:00 1970-01-01 :P 除非时钟为1970-01-01 00:00:00:P
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.