title: Cannot delete cookies that were set in JavaScript on the server
body: <p>I am trying to write PHP code to delete all of the user cookies on my domain.</p>
  
  <p>Here is what I got:</p>
  
  <pre><code>&lt;?php
  $domain = 'www.example.com';
  $deleteExpiration = time() - 60*60*24*365*10; // 10 years ago
  foreach (array_keys($_COOKIE) as $cookie) {
      setcookie($cookie, 0, $deleteExpiration, '/', $domain);
  }
  </code></pre>
  
  <p>Running this code on <a href="http://www.example.com/delete_cookies.php" rel="nofollow noreferrer">http://www.example.com/delete_cookies.php</a> deletes all cookies that were set on the server, but not cookies that were set in JavaScript. </p>
  
  <p>I verified using the Firefox Cookies dialog that the problematic cookies are indeed from (path=/; domain=www.example.com). Using Live HTTP headers, I can see that the following header is sent:</p>
  
  <pre><code>Set-Cookie: CookieName=0; expires=Fri, 12-Mar-1999 19:36:15 GMT; path=/; domain=www.example.com
  </code></pre>
  
  <p>So I believe the setcookie command is working as expected. Firefox is just not honoring the request.</p>
  
  <p>One additional thing that I noticed is that if I set a cookie with <code>domain=www.example.com</code> on the server, then it is listed in the Firefox cookie dialog with <code>domain=".www.example.com"</code>, but if I set the following cookie using JavaScript code then the leading dot is not added.</p>
  
  <p>What am I doing wrong? How can I delete these cookies?</p>