title: Cookies across subdomains and hosts
body: <p>In the application I'm writing using a combination of development environments and languages, I have need of accessing a cookie from two different subdomains, each on a separate host.</p>
  
  <p>The cookie is being set on <code>www.mydomain.com</code> using the PHP code that follows, and I'm attempting to access it from <code>distant.mydomain.com</code> on a separate host.</p>
  
  <pre><code>setcookie('token', base64_encode(serialize($token)), time()+10800, '/', '.mydomain.com');  
  </code></pre>
  
  <p>I'm trying to access the cookie from <code>distant.mydomain.com</code> using the following code:  </p>
  
  <pre><code>if (isset($_COOKIE['token'])) { /* do stuff */ }  
  </code></pre>
  
  <p><strong>The problem: <code>distant.mydomain.com</code> is not finding the cookie.</strong>  The <code>if</code> statement just mentioned returns false, even though the cookie exists.</p>
  
  <p>I have verified that the cookie that is set is for <code>mydomain.com</code> (by checking my Firefox cookies).  I can't think of any reason this wouldn't be working.  </p>
  
  <p>Using the same <code>setcookie</code> code, I have an old application running exclusively on the <code>www.mydomain.com</code> host, and that application is able to access the cookie across domains.  This makes me suspect that the problem has to do with separate hosts.</p>
  
  <p>Just in case any of the following information is pertinent:<br>
  - <code>www.mydomain.com</code> is IIS 6.0<br>
  - <code>distant.mydomain.com</code> is Apache 2.2.9<br>
  - Both servers use PHP 5.2.x<br>
  - Both servers are operating on Windows Server 2003  </p>
  
  <p>If there is any further information I can provide in order to better describe the problem, please let me know!</p>