title: PHP Sessions across sub domains
body: <p>I am trying to set up the following:</p>
  
  <pre><code>auth.example.com
  sub1.example.com
  sub2.example.com
  </code></pre>
  
  <p>If the user visits <code>sub1.example.com</code> or <code>sub2.example.com</code> and they are not logged in, they get redirected over to <code>auth.example.com</code> and can log in. </p>
  
  <p><code>sub1.example.com</code> and <code>sub2.example.com</code> are two separate applications but use the same credentials.</p>
  
  <p>I tried setting the following in my php.ini:</p>
  
  <pre><code>session.cookie_domain = ".example.com"
  </code></pre>
  
  <p>but it doesn't seem to be passing the information from one domain to the other.</p>
  
  <p><strong>[Edit]</strong></p>
  
  <p>I tried the following:</p>
  
  <p><code>sub1.example.com/test.php</code></p>
  
  <pre><code>session_set_cookie_params(0, '/', '.example.com');
  session_start();
  print session_id() . "&lt;br&gt;";
  $_SESSION['Regsitered'] = 1;
  echo '&lt;a href="http://auth.example.com/test.php"&gt;Change Sites&lt;/a&gt;'
  </code></pre>
  
  <p><code>auth.example.com/test.php</code></p>
  
  <pre><code>session_set_cookie_params(0, '/', '.example.com');
  session_start();
  print session_id() . "&lt;br&gt;";
  $_SESSION['Checked'] = 1;
  print_r($_SESSION);
  </code></pre>
  
  <p>The session IDs are exactly the same but when I dump out the <code>$_SESSION</code> variable it doesn't show both keys, just whatever key I set under each domain.</p>