Remove a cookie

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

    A clean way to delete a cookie is to clear both of $_COOKIE value and browser cookie file :

    if (isset($_COOKIE['key'])) {
        unset($_COOKIE['key']);
        setcookie('key', '', time() - 3600, '/'); // empty value and old timestamp
    }
    

提交回复
热议问题