I am trying to set up the following:
auth.example.com
sub1.example.com
sub2.example.com
If the user visits sub1.example.com
or
Had this exact problem - I wanted session values created on x.example.local to be available on example.local and vice-versa.
All solutions I found said to change the Session domain by using
php_value session.cookie_domain .example.local
in .htaccess (or via php.ini or via ini_set).
The catch was I was setting the session.cookie_domain
for all subdomains (so far ok) but also for the main domain. Setting the session.cookie_domain
on the main domain is apparently a no-no.
Basically the way it worked for me:
session.cookie_domain
for ALL SUBDOMAINS.Oh yes, please make sure the domain has a TLD (in my case .local). Http protocol doesn't allow cookies/sessions to be stored on a domain without .tld (ie localhost won't work, but stuff.localhost will).
EDIT: Also make sure you always clear your browser cookies while testing/debugging sessions across subdomains. If you don't, your browser will always send the old session cookie which probably doesn't have the correct cookie_domain set yet. The server will revive the old session and therefore you'll get false negative results. (in many posts it's mentioned to use session_name('stuff') for the exact same effect)