如何删除所有具有相同名称的cookie? [英] How to delete all cookies with the same name?

查看:126
本文介绍了如何删除所有具有相同名称的cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有3个同名的Cookie。
http://clip2net.com/s/jm4CcZ
他们得到了不同的路径( /, / call, / call / login)和其他域( .domain.com, domain.com)。
现在我使用几个setcookie()指令删除它们中的每一个。

I got 3 cookies with the same name on my website. http://clip2net.com/s/jm4CcZ They got different paths ('/', '/call', '/call/login') and different domains ('.domain.com', 'domain.com'). Now I use several setcookie() instuctions to delete each of them.

有没有更聪明的方式一次删除它们?

Is there more smart way to delete them at once?

推荐答案

不是一次全部。如果要删除特定的cookie,则需要使用cookie名称。如果要取消设置所有cookie,可以使用以下命令:

No not all at once. If you want remove the specific cookies you need to use the cookie name. If you want to unset all cookies you can use this:

// 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://php.net/manual/en/function.setcookie.php#Hcom73484

这篇关于如何删除所有具有相同名称的cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆