This one is a beauty…
I have recently been writing a web application that combined AJAX and PHP Session Variables. I soon encountered a problem where it appeared that the session variables were not available form the code loaded by the AJAX call.
The application basically fires off an AJAX call to load a PHP page when a link is selected, and then populates a <DIV> on the same page with the parsed results of that PHP page. Session variables were being used to store some basic ifnromation about the logged in user – user name, etc. – and I was hoping to make use of these in the AJAX loaded code.
After some serious head scratching it became clear that the PHP session variables, whilst being available everywhere else in the application, were not available from any code loaded with AJAX.
Now, whether this is a known issue or not, or whether I’m being dim, I’m not entirely sure and would welcome any input people have to offer. However, in the meantime I’ve ended up passing over a couple of extra parameters with the AJAX GET statement and have used those to regenerate the user related data within the AJAX loaded code.
Because the application is OO designed, this wasn’t a major problem, but actually recognising the problem was a bit time consuming; hopefully this post will save someone else the head-scratching!