title: PHP: Cookie domain / subdomain control
body: <p>I'm working on a site with multiple subdomains, some of which should get their own session.</p>
  
  <p>I think I've got it worked out, but have noticed something about cookie handling that I don't understand.  I don't see anything in the docs that explains it, so thought I would see if anyone here has some light to shed on the question.</p>
  
  <p>If I just do:</p>
  
  <pre><code>session_start();
  </code></pre>
  
  <p>I end up with a session cookie like this:</p>
  
  <p>subdomain.example.net</p>
  
  <p>However, if I make any attempt to set the cookie domain myself, either like</p>
  
  <pre><code>ini_set('session.cookie_domain', 'subdomain.example.net');
  </code></pre>
  
  <p>or like</p>
  
  <pre><code>session_set_cookie_params( 0, "/", "subdomain.example.net", false, false);
  </code></pre>
  
  <p>I end up with a cookie for .subdomain.example.net (note the opening dot), which I believe means "match all subdomains (or in this case sub-subdomains).</p>
  
  <p>This seems to happen with all my cookies actually, not just session. If I set the cookie domain myself, it automatically has the dot prepended, meaning this domain and all subs of it.  If I don't set the domain, then it gets it right by using only the current domain.</p>
  
  <p>Any idea what causes this, and what I can do to control that prepending dot?</p>
  
  <p>Thanks!</p>