我已经使用 php 创建了一个 cookie,现在我需要创建一个用户可以单击以注销的按钮。
这将是取消设置 cookie 的 php 代码:
unset($_COOKIE['access_token']);
但我对如何制作按钮功能非常困惑。有人可以帮我吗?
非常感谢
我已经使用 php 创建了一个 cookie,现在我需要创建一个用户可以单击以注销的按钮。
这将是取消设置 cookie 的 php 代码:
unset($_COOKIE['access_token']);
但我对如何制作按钮功能非常困惑。有人可以帮我吗?
非常感谢
if(isset($_GET['logout'])) {
unset($_COOKIE['access_token']);
header('Location: /');
exit;
}
现场
<a href="?logout">logout</a>
顺便说一句,您可以通过设置过去的时间来删除cookie
setcookie($_COOKIE['access_token'],'',time()-3600);
你应该取消会话
session_destroy()'
实际上最好这样做:
setcookie("myCookie", null, 1); //# This will expire / delete *immediately*
如果你使用
setcookie("myCookie", null, 0), the cookie is still valid until they close their browser.