Reputation: 437
I'm trying to set my PHP $_SESSION and have it usable across all subdomains. This works fine except when trying to retrieve the session from the root domain (www).
If I initiate the session while on www then it will not share with any sub domain. If I initiate the session while on a sub domain it will not share with www.
I have the session_set_cookie_params (index.php) and session.cookie_domain (php.ini) set correctly to .domain.com
When I echo $_COOKIE["PHPSESSID"] on www I get a string of characters that is different from the string of characters used on all sub domains. All sub domains have the same value for $_COOKIE["PHPSESSID"].
I would like to be able to initiate the session on www and be able to use that session on all sub domains as well. Is there any solution to this?
Thank you for any and all help.
Upvotes: 3
Views: 2303
Reputation: 164
Try setting a name for the session
session_name("domain");
before setting the session cookie parameters.
session_name("domain");
session_set_cookie_params(0, '/', '.domain.com');
session_start();
Upvotes: 3