简体   繁体   English

如何在php中删除浏览器的所有cookie

[英]How to delete all the cookies of the browser in php

consider i have three websites in a different server namely example1.com,example2.com,example3.com 考虑我在不同的服务器上有三个网站,即example1.com,example2.com,example3.com

i have tried to clear all the cookies when i click the particular logout page.But, it clear only the current page cookies. 当我单击特定的注销页面时,我试图清除所有cookie。但是,它仅清除当前页面cookie。

i opened all these websites in the browser ..and now when i logout from the example1.com it should clear all the cookies of the browser whichever has been set previously... 我在浏览器中打开了所有这些网站。现在,当我从example1.com注销时,它应该清除浏览器的所有cookie,无论以前设置的是什么...

Thanks in Advance. 提前致谢。

My code:: 我的代码::

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, '/');
    }
}

You can't. 你不能

For obvious security reasons. 出于明显的安全原因。 You can't read (and delete) cookies that belongs to another domain. 您不能读取(和删除)属于另一个域的cookie。 If you could, than all website would have access to all cookies in your computer. 如果可以,那么所有网站都可以访问您计算机中的所有cookie。

Posting it as an answer due to less reputation. 由于声誉较低而将其发布为答案。

basically cookies are save on browsers and relation between browser and web server regarding cookies is that data present at eligible requests so , expiration of cookie is correct method because it means data is no more, by the following two method you delete your cookie form browser 基本上cookie是保存在浏览器上的,并且关于cookie的浏览器与Web服务器之间的关系是在符合条件的请求中存在数据,因此cookie过期是正确的方法,因为这意味着数据不再存在,通过以下两种方法可以从浏览器中删除cookie

1) unset($_COOKIE['my_cookie']); 1)unset($ _ COOKIE ['my_cookie']); 2) setcookie('my_cookie', '', 1); 2)setcookie('my_cookie','',1); // 1 is time of past // 1是过去的时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM