I have a website www.example.com. That will have multiple subdomains that work with a single application or program. For an example, login.example.com will allow the user to log in to the site while system.example.com will allow the user to access an information system, while forums.example.com will allow the user to access forums.
We may need to pass information between the subdomains such as a user id, or a user preference, etc. How do we go about passing information between the sudomains using SESSION variables?
EDIT: I like this idea:
As the first thing in your script:
ini_set('session.cookie_domain', '.example.com' );
You create subdomains to help organize and navigate to different sections of your main website. Within your main domain, you can have as many subdomains as necessary to get to all of the different pages of your website.
Since subdomains effectively replace the domain and count as that domain for pretty much all purposes, and you can't take a subdomain and its domain together, you can't take both.
No, SESSION variables are on the server side so from the client's perspective, they cannot change them. That's one of the main reasons we use Sessions instead of cookies.
To share cookies across subdomains, you can simply create cookies with the domain directive set to the parent domain, in this case, example.com, rather than either of the specific subdomains. In my browser, I have the index and product detail pages open.
1) the subdomains should use the same path to save session files
2) modify your
php.ini session.cookie_domain = ".example.com"
or .htaccess php_value session.cookie_domain .example.com
or inside of the script ini_set('session.cookie_domain', '.example.com' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With