PHP _SESSION not updating from ajax call
<p>I cant get this to work. I have a php with Html and in html a submit button that call a .js . in that js i call with ajax another php file. So i cant get the _SESSION variable to be present for the second php that is called by ajax. here is the code.</p>

<pre><code>&lt;?php
session_start();

if(isset($_POST['enviar']))
{
    $_SESSION['dni']=$_POST['dni_reg'];
    $_SESSION['pass']=$_POST['pwd'];
    $_SESSION['email']=$_POST['email_reg'];
    $_SESSION['afi']=$_POST['afi'];
    $_SESSION['conf']=$_POST['pwd2'];

    session_write_close();
}
?&gt;

----- part of the html----

&lt;form action="" method="post" name="form3" onsubmit="return campos_completos_registro()"&gt;
                   &lt;table width="579" border="0" cellpadding="0" cellspacing="5"&gt;                       
                       &lt;tr&gt;
                            &lt;td valign="middle" align="right" class="texto_azul11"&gt;Tipo de Documento&amp;nbsp;&lt;/td&gt;
                       &lt;td valign="middle" align="right" class="texto_azul11"&gt;N&amp;uacute;mero de Documento&amp;nbsp;&lt;/td&gt;
                           &lt;td valign="middle" height="20"&gt;&lt;input type="text" name="dni_reg" id="dni_reg" class="input_ct"/&gt;&lt;/td&gt;
                       &lt;/tr&gt;
                       &lt;tr&gt;&lt;td height="10"&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
                       &lt;tr&gt;
                            &lt;td valign="middle" align="right" class="texto_azul11"&gt;Fecha de Nacimiento&amp;nbsp;&lt;/td&gt;
                           &lt;td valign="middle" height="20"&gt;&lt;input type="text" name="dia" id="dia" class="input_fecha" maxlength="2" /&gt;-&lt;input type="text" name="mes" id="mes" class="input_fecha" maxlength="2" /&gt;-&lt;input type="text" name="anio" id="anio" class="input_fecha" maxlength="4" /&gt;&amp;nbsp;(dd-mm-aaaa)&lt;/td&gt;
                       &lt;/tr&gt;
                       &lt;tr&gt;&lt;td height="10"&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
                       &lt;tr&gt;
                            &lt;td valign="middle" align="right" class="texto_azul11"&gt;Nro de Carnet de Prepaga&amp;nbsp;&lt;/td&gt;
                           &lt;td valign="middle" height="20"&gt;&lt;input type="text" name="afi" id="afi" class="input_ct"  /&gt;&lt;/td&gt;
                       &lt;/tr&gt;
                       &lt;tr&gt;&lt;td height="10"&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
                       &lt;tr&gt;
                            &lt;td valign="middle" align="right" class="texto_azul11"&gt;Email&amp;nbsp;&lt;/td&gt;
                           &lt;td valign="middle" height="20"&gt;&lt;input type="text" name="email_reg" id="email_reg" class="input_ct"   /&gt;&lt;/td&gt;
                       &lt;/tr&gt;
                       &lt;tr&gt;&lt;td height="10"&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
                       &lt;tr&gt;
                           &lt;td valign="middle" align="right" class="texto_azul11"&gt;Contrase&amp;ntilde;a&amp;nbsp;&lt;/td&gt;
                           &lt;td valign="middle" height="20"&gt;&lt;input type="password" name="pwd" id="pwd" class="input_ct"/&gt;&lt;/td&gt;
                       &lt;/tr&gt;
                       &lt;tr&gt;&lt;td height="10"&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
                       &lt;tr&gt;
                           &lt;td valign="middle" align="right" class="texto_azul11"&gt;Repetir Contrase&amp;ntilde;a&amp;nbsp;&lt;/td&gt;
                           &lt;td valign="middle" height="20"&gt;&lt;input type="password" name="pwd2" id="pwd2" class="input_ct"/&gt;&lt;/td&gt;
                       &lt;/tr&gt;
                       &lt;tr&gt;&lt;td height="10"&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
                       &lt;tr&gt;
                           &lt;td valign="middle"&gt;&lt;/td&gt;
                           &lt;td valign="middle" height="20"&gt;&lt;input type="submit" name="enviar" value="" class="enviar" /&gt;&lt;/td&gt;
                       &lt;/tr&gt;
                   &lt;/table&gt;
                   &lt;/form&gt;
</code></pre>

<p>.js file</p>

<pre><code>function objetoAjax(){
    var xmlhttp=false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }

    if (!xmlhttp &amp;&amp; typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}
function sanitizedni()
{
    var resultado = "";

    if (resultado == "") 
    {
        ajax = objetoAjax();

        ajax.open("GET", 'sanitizedni.php?DNI=1', false);

        ajax.onreadystatechange = function () 
        {
            if (ajax.readyState == 4) 
            {
                resultado = ajax.responseText;
            }
        }
    }
    ajax.send(null);

    return resultado;
}
function campos_completos_registro()
{
    var error = "";

    error += sanitizedni();


    if(error != "")
    {
    alert(error);
    return false;
    }
   return true;


}
</code></pre>

<p>sanitizedni.php</p>

<pre><code>&lt;?php
  session_start();
  $_SESSION['dni']=1111;

  echo $_SESSION['dni'];

?&gt;
</code></pre>

<p>Now that SESSION['dni'] in sanitizedni is the one that is saved to the session cookie.
and the first on in the php $_SESSION['dni']=$_POST['dni_reg'];
is not saved. i think this code is executed last. 
i want $_SESSION['dni']=$_POST['dni_reg']; to be passed to sanitizedni.php.</p>

<p>so How can i do what i want to do...?? </p>
