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:

  1. Destroying session on closing browser or tab or body unload (PHP)
  2. OOP - What are Classes & objects? Advantages and Disadvantages of OOP!
  3. Problems Using Absolute Paths with SSL