delete cookie in php

前端 未结 5 925
心在旅途
心在旅途 2021-01-28 06:01

I am trying to delete a cookie.

I am using setcookie(\"PHPSESSID\", \"\", time() - 6400); which deletes the cookie just fine.

However it is not enti

5条回答
  •  情书的邮戳
    2021-01-28 06:13

    using setcookie("PHPSESSID", "", time() - 6400); expires the cookie like 2 hours ago, try using setcookie("PHPSESSID", "", 1); to expire it at epoch January 1st, 1970.

    if that doesn't work you can try adding in the path like this setcookie("PHPSESSID","",time()-6400,"/");

    You can try this example from http://www.php.net/manual/en/function.setcookie.php#73484 to remove all cookies, but I'm since this seems to be some sort of supercookie who knows..

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

提交回复
热议问题