如何删除浏览器在一次请求期间添加的所有cookie?

I'm trying to delete all cookies with javascript (or php) that a browser request has added to my computer, included the ones added by analytics and iframe. I've tried all solutions from stack and none worked.

For example, I open index.php that adds its own cookies, and has in the HTML document Google Analytics script (few other cookies), facebook like button (another cookie), advertising scripts (other cookies). I'll end up with the following:

  • server cookies
  • Google analytics cookies
  • Facebook Like cookies
  • advertising third parties cookies

How do I delete everything, either with a php script (ajax request) or javascript?

Note: cookies are from different domains, as explained above

You can neither read nor write (and that means delete) cookies from other domains for security reasons. This is especially true for HTTP-only cookies.

See also How can my website delete another site's cookies?

As stated, you need human interaction through browser CTRL+SHIFT+DEL for clearing anything but your own scripting domain.. Here goes

<?php
$status = "";
foreach($_COOKIE as $k=>$v) {

    # each $k corresponds to a cookie
    # send cookie header, that tells browser to remove due to expired has passed
    # see http://php.net/manual/en/function.setcookie.php for more details
    setcookie($k, $v, time()-1000000);
$status .= "unset $k<br/>
";
}
echo $status;
?>