Hello,
I'm trying to share login information (stored in sessions) between 2 subdomains, ie: sub1.example.com and sub2.example.com. Both subdomains are hosted on the same server.
I've tried several things (like using session_set_cookie_params() to set the cookie domain) and just using a custom php.ini, both to set the cookie domain of the session cookie to ".example.com".
On sub1.example.com I have a test script which sets a session (and displays it once it's been set on each page reload). This works fine. I get:
Quote:
PHPSESSID c6425dc25a99752d980caeac914f7e48
Array
(
[test] => test
)
Array
(
[lifetime] => 0
[path] => /
[domain] => .example.com
[secure] =>
[httponly] =>
)
|
This is what you get when I output the session name, session ID, below that the contents of $_SESSION and finally the result of session_get_cookie_params(). As you can see, the session is set.
Now when I run this exact same script on sub2.example.com, I get:
Quote:
PHPSESSID c6425dc25a99752d980caeac914f7e48
Array
(
)
Array
(
[lifetime] => 0
[path] => /
[domain] => .example.com
[secure] =>
[httponly] =>
)
|
As you can see, same session name/id so you'd think it would work, BUT the $_SESSION array is suddenly empty!
Now when I go back to sub1.example.com after visiting sub2.example.com, I notice that over there the $_SESSION variable is empty too.
Strange. First it's set on sub1, then I visit sub2 and it seems to reset the session instead of using the session date set by sub1.
Any idea what might be causing this?