Session Data loses while making an ajax call to a file on IIS server hosting PHP. A very common issue stated on the PHP session_start page as well
http://php.net/manual/en/function.session-start.php
http://php.net/manual/en/function.session-start.php
/***** sess1.php *****/
session_start();
$_SESSION["key1"] = "testvalue";
header("Location: sess2.php");
/***** sess2.php *****/
session_start();
echo "key1 = '".$_SESSION["key1"]."'";
PROBLEM:
All session data is lost after a header redirect from the first page on
which the session is initialized. The problem is, the PHPSESSID cookie
is not being sent to the browser (ANY browser, IE or Mozilla) on the
initial session page with the header("Location: ...") redirect. This is
unrelated to client cookie settings - the set-cookie: header just isn't
sent.
SOLUTION:
I was able to remedy the problem by switching to the ISAPI DLL version.
This seems to be an MS/IIS bug, NOT a PHP bug - go figure. I hope this
saves you some headaches especially with your user authentication
scripts!!
*same case happens if we make an ajax request to a file
I am still looking for a way to switch to ISAPI dll version though?
Best way I could get was to use cookies in such case scenario if possible.
Things work well on Apache server though but I am still looking for a solution to this....?