Reputation: 337
I got 3 cookies with the same name on my website. http://clip2net.com/s/jm4CcZ They got different paths ('/', '/call', '/call/login') and different domains ('.domain.com', 'domain.com'). Now I use several setcookie() instuctions to delete each of them.
Is there more smart way to delete them at once?
Upvotes: 0
Views: 2924
Reputation: 3434
No not all at once. If you want remove the specific cookies you need to use the cookie name. If you want to unset all cookies you can use this:
// unset cookies
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, '/');
}
}
This is a function that is published on http://php.net/manual/en/function.setcookie.php#Hcom73484
Upvotes: 1