Problems deleting cookies, won't unset

2020-02-05 01:30发布

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);

or

setcookie("name", '', time()-3600);

But when I check the cookies in the cookies dialog in Firefox, it's still there with the same value. I set this cookie using the following line:

setcookie("name", $value, time() + 259200, $path);

I found this question on stackoverflow: , but none of the answers solved the problem. I also tried putting all paramaters in, like the author said, but it had no effect.

Does anyone see the problem?

17条回答
smile是对你的礼貌
2楼-- · 2020-02-05 02:30

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']);
查看更多
三岁会撩人
3楼-- · 2020-02-05 02:33

I sugest to using

ob_start();

at the firts l

查看更多
成全新的幸福
4楼-- · 2020-02-05 02:34

Just like is said in the correct answer (I want it to send an updated one), to unset, every parameter used to set the cookie is necessary, even secure and httponly

Set

setcookie("name_cookie", $name_value, 0, '/', $domain, false, true);

Unset

setcookie("name_cookie", '', time()-1000, '/', $domain, false, true);
查看更多
狗以群分
5楼-- · 2020-02-05 02:35

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.

查看更多
\"骚年 ilove
6楼-- · 2020-02-05 02:36

This did the trick for me:

setcookie("brownie","",1,'/');
unset($_COOKIE["brownie"]);
查看更多
登录 后发表回答