user198729
user198729

Reputation: 63686

How to delete all cookies in PHP?

setcookie('id', null, 1, "/", ".domain.name");

The above will only delete a specific cookie, but how to delete them all?

Upvotes: 3

Views: 19813

Answers (3)

InfiniteGFX
InfiniteGFX

Reputation: 1

    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, '/');
        }
    }

Upvotes: 0

AJ.
AJ.

Reputation: 1

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

$_COOKIE=array();

Upvotes: -11

Michal M
Michal M

Reputation: 9480

This should do the trick:

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

Upvotes: 13

Related Questions