August 22nd, 2009Pass Sessions between subdomains in php
Recently was working on a social networking project, where site was divided into subdomains based on states. Thus if user wanted to swtich from 1 state to another (i.e. 1 subdomain to other), system had to pass the user session from 1subdomain to another subdomain.
Here is the solution:
1) If you have the access to php.ini file then you need to add this line to your php.ini file
session.cookie_domain = .mydomain.com
2) If you dont have access to the php.ini file then you need to add the following before the session.start() function on any page which creates the session cookie.
ini_set(”session.cookie_domain”, “.mydomain.com”);
Incase there is any better or alternate way then kindly share with me.
Thanks for reading!
Related posts:








