根据 http://php.net/manual/en/function.setcookie.php,他们提供了以下示例来删除cookie:
setcookie ("TestCookie", "", time() - 3600);
删除 Cookie 的选定答案建议如下:
setcookie('Hello', null, -1, '/');
应该是time()-3600
、-1
,还是别的什么?
附带说明一下,null
值还是""
首选值?
试试这个
if (isset($_COOKIE['TestCookie']))
{
// removing the cookie
unset($_COOKIE['TestCookie']);
// resetting the cookie
setcookie('TestCookie', null, -1, '/');
return true;
} else {
return false;
}
由于将根据客户端时钟检查cookie过期时间,因此最佳选择是:
setcookie('Hello', null, 1, '/');
然后,您可以确保它将立即过期。
除非时钟是 00:00:001970-01-01 :P