title: Maintain PHP session in Facebook AJAX request
body: <p>I have a Facebook iframe app. As soon as the app authorisation is confirmed I grab some data from the signed request an put it into session:</p>
  
  <pre><code>&lt;?php
      session_start();
      $signed_request = $_REQUEST["signed_request"];
      list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
      $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
      if(empty($data["user_id"])) {
          echo("&lt;script&gt; top.location.href='$auth_url'&lt;/script&gt;");
          exit;
      }
      $_SESSION['fb_id'] = $data['user_id'];
  ?&gt;
  </code></pre>
  
  <p>Simple, right?  So now the user can interact with my app, and the final user action triggers an AJAX request.  I'm using jQuery for this:</p>
  
  <pre><code>$.ajax({
      type:'POST',
      url:'include/handler.php',
      data:'name=value',
      success: function(msg) {
          alert("Success: "+msg);
      },
      error: function(msg) {
          alert("Fail: "+msg);    
      }
  });
  </code></pre>
  
  <p>So then in handler.php, I need to use that previously saved session value, but the session is empty.</p>
  
  <pre><code>&lt;?php
      session_start();
      echo $_SESSION['fb_id'];
  ?&gt;
  </code></pre>
  
  <p>Obviously these code snippets are simplified, but can anyone explain this to me? I've got a feeling that I'm doing something stupid, but it's been a long day.</p>