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);
This did the trick for me:
setcookie("brownie","",1,'/');
unset($_COOKIE["brownie"]);
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']);
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, "/");
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.
I sugest to using
ob_start();
at the firts l
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.