how to delete all cookies of my website in php how to delete all cookies of my website in php php php

how to delete all cookies of my website in php


PHP setcookie()

Taken from that page, this will unset all of the cookies for your domain:

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

http://www.php.net/manual/en/function.setcookie.php#73484


$past = time() - 3600;foreach ( $_COOKIE as $key => $value ){    setcookie( $key, $value, $past, '/' );}

Even better is however to remember (or store it somewhere) which cookies are set with your application on a domain and delete all those directly.
That way you can be sure to delete all values correctly.


I agree with some of the above answers. I would just recommend replacing "time()-1000" with "1". A value of "1" means January 1st, 1970, which ensures expiration 100%. Therefore:

setcookie($name, '', 1);setcookie($name, '', 1, '/');