Remove a cookie

后端 未结 22 1357
没有蜡笔的小新
没有蜡笔的小新 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:37

    Just set the expiration date to one hour ago, if you want to "remove" the cookie, like this:

    setcookie ("TestCookie", "", time() - 3600);
    

    or

    setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", "example.com", 1);
    

    Source: http://www.php.net/manual/en/function.setcookie.php

    You should use the filter_input() function for all globals which a visitor can enter/manipulate, like this:

    $visitors_ip = filter_input(INPUT_COOKIE, 'id');
    

    You can read more about it here: http://www.php.net/manual/en/function.filter-input.php and here: http://www.w3schools.com/php/func_filter_input.asp

提交回复
热议问题