title: AJAX call destroys session wiht no apparent reason
body: <p>I know it looks like a banal question but please read the whole thing, I am stumped by this.</p>
  
  <p>I have an AJAX call on one of my pages, it's a dynamic messaging system:</p>
  
  <pre><code>function validateMessage(){
  
    var recipient = document.getElementById("send_to").value;
    var subject = document.getElementById("popup_subject").value;
    var message = document.getElementById("popup_message").value;
  
    var parameters="message="+message+"&amp;recipient="+recipient+"&amp;subject="+subject;
  
     if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
     }
     else
     {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
  
     xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
          document.getElementById("error_mess").innerHTML = xmlhttp.responseText;
      }
    }
  
    xmlhttp.open("POST","include/send_message.php",false);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    xmlhttp.send(parameters);
  
    }
  </code></pre>
  
  <p>It's implemented as synchronous for a reason, that's not the issue here. I tried switching to asynchronous and the problem remains.</p>
  
  <p>This is the send_message.php file, it just grabs the POST variables and saves them into the database:</p>
  
  <pre><code>&lt;?php
  session_start();
  include('db.php');
  dbConnect();
  
  $message=$_POST['message'];
  $subject=$_POST['subject'];
  $recipient=$_POST['recipient'];
  
  $result=mysql_query("select * from korisnici where username='$recipient' ") or die(mysql_error());
  $row=mysql_fetch_array($result);
  $num=mysql_num_rows($result);
  
  if($recipient=="Poruka za..." || $subject=="Naslov..." || $message=="Poruka" || $recipient=="" || $subject=="" || $message=="")
      echo "&lt;p style='color:red;'&gt;Morate popuniti sva polja.&lt;/p&gt;";
  elseif($num==0)
      echo "&lt;p style='color:red;'&gt;Korisnik ne postoji.&lt;/p&gt;";
  else{
      $prima=$row['id_user'];
      $salje=$_SESSION['id_user'];
      mysql_query("insert into poruke (salje, prima, naslov, poruka)
          values ('$salje', '$prima', '$subject', '$message') ") or die(mysql_error());
      echo "&lt;p style='color:green;'&gt;Poruka uspješno poslata!&lt;/p&gt;";
  }
  
  ?&gt;
  </code></pre>
  
  <p>However, when I tried to save the $_SESSION['id_user'] variable (as the sender) I found a problem - it turns out the session is being destroyed every time this AJAX call runs! So doing <code>print_r($_SESSION)</code> right after <code>session_start()</code> prints an empty array.</p>
  
  <p>The session is alive on the original page itself, and refreshing that page keeps the session alive. Only when I click the button to make the AJAX call, the session disappears. Can someone spot the issue?</p>