“The Problem:”
I call with ajax a handler.php file multiple times.
In the handler.php I have:
session_start();
$_SESSION['foo'] .= 'abc';
echo 'Session var: '.$_SESSION['foo'].'<br>';
Now, what I see is:
Session var: abc
Session var: abc
Session var: abc
... etc
Instead of:
Session var: abc
Session var: abcabc
Session var: abcabcabc
Whats the problem?
I hope you get the point:)
EDIT: I forgot to mention that sometimes I get the second (what normally expect), but most of the time I get the first version.
I found the solution… so after 4 months I can answer it 🙂
The solution seems very easy but I did not think about it first. I thought it was a “deeper” problem, because my code is very long.. So the solution was to include session_start(); in the “index.php” file, (where you call the ajax itself or where you included the .js file).
I hope it helps if someone in the future run into these silly “simptoms”.*
So, even if you don’t use sessions in the “index.php” file, you have to include session_start() there if you wanna use sessions in the ajax “handler” php file.
(You have to include session_start(); to hander.php too, of course.)