Reputation: 11609
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 (or any static variable that are implemented in my classes on other PHP files), it isn't recognized (I echo
it, and I have a 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 my PHP file, I test my variable like so:
require_once '../Account.php';
$temp=Account::getCurrentAccount()->getId();
echo($temp);
exit;
Does someone have an idea?
Upvotes: 0
Views: 90
Reputation: 8301
Add this to your ajax .php file
if( !isset( $_SESSION ) ){ session_start(); }
Ideally, you would have that in some common config file...
Upvotes: 1