| re: PHP Session problem with AJAX
Hi, of course:
I have the folloving function, at authentification the login.php file is requested, in that file if the user data is ok, I would like to start a session, but that event does not occur. I have all on one page, the login form is replaced by the content of the page after the authentification was made.
The function which makes the request for the login.php :
function autentificare()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return;
}
var url="./login.php"+"?andrascache="+new Date().getTime();
utilizator=document.form.nume_utilizator.value;
parola=document.form.parola.value;
xmlHttp.onreadystatechange=proceseazaLogarea;
xmlHttp.open("GET",url+'&nume_utilizator='+utiliza tor+'&parola='+parola,true);
xmlHttp.send();
}
function proceseazaLogarea()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
raspuns=xmlHttp.responseText;
if(raspuns=='eroare'){
document.getElementById('comentariu_p').innerHTML= '<b>Parola incorecta!<b>';
document.getElementById('comentariu_p').className= 'erori';
}
else
{
cerereContinut();
}
}
}
Below is the login.php content, for testing I let only
<?php
/*below the session should start, but in FireBug I can see that the session variable value is empty, as below:
Array
(
[nume_utilizator] =>
) */
session_start();
$utilizator=$_GET['nume_utilizator'];
$_SESSION['nume_utilizator']=$_utilizator;
print_r($_SESSION);
echo 'ok'; //authentification ok
?>
|