1

我已经使用 php 创建了一个 cookie,现在我需要创建一个用户可以单击以注销的按钮。

这将是取消设置 cookie 的 php 代码:

 unset($_COOKIE['access_token']);  

但我对如何制作按钮功能非常困惑。有人可以帮我吗?

非常感谢

4

3 回答 3

1

if(isset($_GET['logout'])) {

unset($_COOKIE['access_token']);

header('Location: /');

exit;

}

现场

<a href="?logout">logout</a>

于 2011-02-28T16:24:11.893 回答
1

顺便说一句,您可以通过设置过去的时间来删除cookie

setcookie($_COOKIE['access_token'],'',time()-3600);

你应该取消会话

session_destroy()'
于 2011-02-28T16:26:00.453 回答
1

实际上最好这样做:

setcookie("myCookie", null, 1); //# This will expire / delete *immediately*

如果你使用

setcookie("myCookie", null, 0), the cookie is still valid until they close their browser.
于 2012-09-21T06:20:33.027 回答