2013-03-18 53 views
0

我想删除一个cookie,它不起作用。我的cookie不想删除自己

这里是代码,任何想法?

setcookie("candidate_site_search", serialize($model->getAttributes()), strtotime('next year'), '/'); 

    if (isset($_GET['clearFilters']) && ($_GET['clearFilters'] == 1)) { 
     //die('cf'); 
     $model->unsetAttributes(); 
     setcookie("candidate_site_search", serialize($model->getAttributes()), time() - 60 * 60 * 24 * 30); 
     if (isset($_COOKIE['candidate_site_search'])) 
      unset($_COOKIE['candidate_site_search']); 
     if (isset($_COOKIE['site_search'])) 
      unset($_COOKIE['site_search']); 
     $this->redirect(array('/candidate/search')); 
    } 

删除后,我重定向到请求来的地址。

仍然没有任何反应

PS:我觉得这个cookie是与查克·诺里斯,或至少超人......

+0

这是否'if'评价真的吗? – 2013-03-18 08:03:57

+0

使用与设置cookie时相同的可选参数来删除cookie。像路径,域名等。 – 2013-03-18 08:04:03

+0

检查此[http://stackoverflow.com/questions/686155/remove-a-cookie](http://stackoverflow.com/questions/686155/remove-a-cookie) – 2013-03-18 08:04:17

回答

2

的问题是最有可能在你的服务器上设置的日期/时间关于客户的时间。

举例来说,如果你的服务器是GMT + 2和你的客户是GMT,那么上面的代码会告诉客户在到期GMT + 1饼干这仍然是在未来的客户端。

只需使用一次即waaay回到了过去,所以你消除任何时区的问题:

setcookie("name_of_cookie", "", time() - 60 * 60 * 24 * 30); // should do it 
+0

嗯,这可能是 – 2013-03-18 08:06:28

+0

它不是这个:( – 2013-03-18 08:07:37

+0

+1为原始想法 – 2013-03-18 08:08:03