title: Maintaining the same Session in Child Window
body: <p>When a user arrives at my site, a session is started for them. There is a point where a <strong>child window</strong> is spawned using <strong>JavaScript</strong> on my sites home page.</p>
  
  <p>This child window goes to Twitter site to authenticate the user and it gets <strong>redirected</strong> back to a script on my site which stores some variables in a SESSION. </p>
  
  <p>I have found out that the PHP script in the child window isn't aware of the session and session_id that is set already and it therefore starts a new session which means the parent window (index.php) can not access those session variables.</p>
  
  <p>I am <strong>baffled</strong>. What can I do? </p>
  
  <h2>Update</h2>
  
  <p>Here is my code, but its not my code that is the problem, its the <strong>implementation</strong> that I am having trouble with.</p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>&lt;?php session_start(); ?&gt;
  </code></pre>
  
  <p><strong>oauth.php</strong> //child window</p>
  
  <pre><code>&lt;?php session_start();
  
  $_SESSION['screen_name'] =  $twitterInfo-&gt;screen_name;
  
  $_SESSION['profile_image_url'] = $twitterInfo-&gt;profile_image_url;
  
  ?&gt;
  </code></pre>
  
  <p>When child window closes and I use AJAX to check a screen_name like so, it returns a no match as the child window oauth.php is using a <strong>different session</strong> (id).</p>
  
  <pre><code>&lt;?php session_start();
  
      sleep(1);
  
      if(isset($_SESSION['screen_name'])){
  
          echo 'done';
          exit;
  
      }else{
  
          echo session_id().$_SESSION['screen_name'];
          exit;
  
      }
  ?&gt;
  </code></pre>