开发者

How to delete all cookies in PHP?

开发者 https://www.devze.com 2022-12-14 15:39 出处:网络
setcookie(\'id\', null, 1, \"/\", \".domain.name\"); The above will only delete a specific cookie, but ho开发者_如何学编程w to delete them all?This should do the trick:
setcookie('id', null, 1, "/", ".domain.name");

The above will only delete a specific cookie, but ho开发者_如何学编程w to delete them all?


This should do the trick:

foreach ($_COOKIES as $c_id => $c_value)
{
    setcookie($c_id, NULL, 1, "/", ".domain.name");
}


    if (isset($_SERVER['HTTP_COOKIE']))
    {
        $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
        foreach ($cookies as $cookie)
        {
            $parts = explode('=', $cookie);
            $name = trim($parts[0]);
            setcookie($name, '', time() - 1000);
            setcookie($name, '', time() - 1000, '/');
        }
    }


Man, isn't it easier to just wipe out all cookies like this:

$_COOKIE=array();
0

精彩评论

暂无评论...
验证码 换一张
取 消