Remove a cookie

后端 未结 22 1608
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 16:16

When I want to remove a Cookie I try

unset($_COOKIE[\'hello\']);

I see in my cookie browser from firefox that the cookie still exists. How

22条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 16:34

    That will unset the cookie in your code, but since the $_COOKIE variable is refreshed on each request, it'll just come back on the next page request.

    To actually get rid of the cookie, set the expiration date in the past:

    // set the expiration date to one hour ago
    setcookie("hello", "", time()-3600);
    

提交回复
热议问题