无法删除php设置cookie [英] Can't delete php set cookie

查看:111
本文介绍了无法删除php设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在php

  setcookie('alert_msg',' '); 

我已尝试以这种方式取消设置

  setcookie('alert_msg',''); 
setcookie('alert_msg',false);
setcookie('alert_msg',false,1);
setcookie('alert_msg',false,time() - 3600);
setcookie('alert_msg','',1,'/');

,它仍然不会取消$ _COOKIE ['alert_msg']中的cookie值。 p>

我已在Firefox和Chrome中尝试过



代码示例:

  if(isset($ _ COOKIE ['alert_msg'])){
$ this-> set('alert_msg',$ _COOKIE ['alert_msg']) ;
unset($ _ COOKIE ['alert_msg']);
setcookie('alert_msg','',1,'/');
}


解决方案



由于您未将路径参数传递给 setcookie 函数,在这种情况下,cookie将仅为当前目录设置,并且可以使用,并且只能从该目录中取消设置。



可能的解决方案是传递 path 值为 / 。因此,cookie可以从应用程序的任何部分使用和取消设置。


I've set a cookie through this call in php

setcookie('alert_msg', 'you have the add badge');

I have tried unsetting it this way

setcookie('alert_msg', '');
setcookie('alert_msg', false);
setcookie('alert_msg', false, 1);
setcookie('alert_msg', false, time()-3600);
setcookie('alert_msg', '', 1, '/');

and it still won't unset the cookie value in $_COOKIE['alert_msg'].

I have tried in both Firefox and Chrome

Code sample:

if (isset($_COOKIE['alert_msg'])) {
    $this->set('alert_msg', $_COOKIE['alert_msg']);
    unset($_COOKIE['alert_msg']);
    setcookie('alert_msg', '', 1, '/');
}

解决方案

Checkout the cookie path.

Since you are not passing the path parameter to the setcookie function, in this case the cookie will be set for the current directory only and can be used and can be unset from that directory only.

Possible solution is to pass the path value as /. So that cookie can be used and unset from any part of application.

这篇关于无法删除php设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆