沃梦达 / 编程问答 / php问题 / 正文

如何在php中删除我网站的所有cookie

how to delete all cookies of my website in php(如何在php中删除我网站的所有cookie)

本文介绍了如何在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

这篇关于如何在php中删除我网站的所有cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在php中删除我网站的所有cookie

基础教程推荐