如何在php中删除我网站的所有cookie
我想知道是否可以在用户单击注销时删除我网站的所有 cookie,因为我使用它作为删除 cookie 的功能,但它无法正常工作:
I'm wondering if I can delete all my website's cookies when a user click on logout, because I used this as function to delete cookies but it isn't work properly:
setcookie("user",false);
有没有办法在 PHP 中删除一个域的 cookie?
Is there a way to delete one domain's cookies in PHP?
推荐答案
PHP setcookie()
取自该页面,这将取消您域的所有 cookie:
Taken from that page, this will unset all of the cookies for your domain:
// unset cookies
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000);
setcookie($name, '', time()-1000, '/');
}
}
http://www.php.net/manual/en/function.setcookie.php#73484
相关文章