正确的过期值以删除cookie

时间:2014-12-19 17:57:49

标签: php cookies

http://php.net/manual/en/function.setcookie.php,它们提供以下示例来删除cookie:

setcookie ("TestCookie", "", time() - 3600);

Remove a cookie的选定答案建议如下:

setcookie('Hello', null, -1, '/');

应该是time()-3600-1还是其他什么?

在旁注中,值为null""首选?

2 个答案:

答案 0 :(得分:0)

试试这个

if (isset($_COOKIE['TestCookie'])) 
{
    // removing the cookie
    unset($_COOKIE['TestCookie']);

    // resetting the cookie
    setcookie('TestCookie', null, -1, '/');

    return true;
} else {
    return false;
}

答案 1 :(得分:0)

由于将根据客户端时钟检查cookie到期时间,因此最佳选择是:

setcookie('Hello', null, 1, '/');

然后你可以确保它会立即过期。

除非时钟是00:00:00 1970-01-01:P