Possible Duplicate:
AJAX request fails to process $_SESSION variable
I have some strange issue about the $_SESSION. I have a JavaScript file that processes an AJAX request. This request processes a PHP file (which works fine). But when I want to call in this very PHP file my $_SESSION variable, it isn’t recognized (I echo it, and I get the 500 error).
In the JS file, I have:
$.ajax({
type: "POST",
url: "../classes/ajax/myfile.php",
data: "comment="+encodeURIComponent(text),
success: function(msg){
/* PHP returns the automatically assigned ID of the new comment */
}
});
and in myfile.php, ($_SESSION[‘user’] is serialized in ./classes/account.php), I test my variable like so:
if (isset($_SESSION['user'])) {
echo('hello world !');
exit;
}
Here $_SESSION seems not to be set. But, when called in other php files of ./classes, it works just fine.
Does someone have an idea how to fix this?
You need to call
session_start()before