Thanks in advance.
I have a local installation of Xampp. My sites are setup as follows. I have my main domain i.e. 'domain' installatiopn directory:
Within this i have a subdomain setup i.e. '
subdomain.domain' installation directory:
The goal of this is to have a single sign on on the main domain site and be able to access the same session data when the user accesses the subdomain site (and thus not have to re-authenticate the user once they have logged into the domain portal site).
I create the session in my domain index.php as follows:
session_set_cookie_params(0, '/', '.3pccap'); session_name('mysessionname'); session_start();
I've added a var_dump(
$_SESSION); on each index.php page to confirm what session data is available. Once I log into my main domain, the session if populated with the users data. I then navigate to my subdomain site which also runs a var_dump of the session variable. The variable is displaying as an empty array.
I have attempted setting the session cookie domain within my php.ini file, no change in behaviour.
Any assistance is most appreciated.Answer1:
You need to make the Session cookie visible for your subdomain (thus, calling the
session_set_cookie on <strong>both</strong>, your domain and your subdomain):
session_set_cookie_params (0, '/', '.domain.com'); session_name('mysessionname'); session_start();<hr />
EDIT (From comments, which solved the issue)
A domain hostname should consist of two parts (even for local development), e.g. domain.local instead of domainAnswer2:
When COOKIES are set, there is a parameter that allows you to specify the PATH and DOMAIN, if you set the DOMAIN to "domain.com" and the PATH to "/" this will make the COOKIE available accross all subdomains, some old browsers require the DOMAIN to use a leading dot(.) ".domain.com"...
<a href="http://php.net/en/set_cookie" rel="nofollow">Checkout the params on this page</a>, session_set_cookie_params also has the DOMAIN and PATH arguments