Problems deleting cookies, won't unset

后端 未结 18 669
死守一世寂寞
死守一世寂寞 2020-12-09 15:33

I\'ve tried searching the php manual and internet on how to delete cookies and I\'ve tried it the exact same way they all say:

setcookie(\"name\", \'\', 1);
         


        
相关标签:
18条回答
  • 2020-12-09 16:20

    This did the trick for me:

    setcookie("brownie","",1,'/');
    unset($_COOKIE["brownie"]);
    
    0 讨论(0)
  • 2020-12-09 16:21

    I'm surprised no one has posted this yet, but this works perfectly for me:

    To CREATE or CHANGE cookie by name:

    $_COOKIE['myCookieName'] = 'I can be changed to whatever u want';
    

    To DELETE a cookie by name:

    unset($_COOKIE['myCookieName']);
    
    0 讨论(0)
  • 2020-12-09 16:23

    Happens to me as well one in ten times though. I guess its a problem with the way we code.

    This is my code

    setcookie("token", "", time() - 36000, "/");
    
    0 讨论(0)
  • 2020-12-09 16:26

    set a cookie

    setcookie('cookiename', $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day

    unset cookie

    setcookie('cookiename', '', time() - 3600, "/");

    No need to panic. Just copy function you use to set cookie and now minus the time. Do not get confuse, make it easy and clear.

    0 讨论(0)
  • 2020-12-09 16:27

    I sugest to using

    ob_start();
    

    at the firts l

    0 讨论(0)
  • 2020-12-09 16:27

    Sometimes you saved the cookie in a different path than you're trying to delete/uset it in.

    Go into eg. Chrome cookie settings and check the cookie path, then add the path to the setcookie command, and delete it like this:

    setcookie( "my_cookie_name","",1,'/mypath');
    

    Trying to delete or unset a cookie that is saved in the wrong path will not work and can be very frustrating.

    0 讨论(0)
提交回复
热议问题