PHP Sessions across sub domains

User will  login or set sessions at auth.domain.com and can use that session all the sub domains of that domain. the session will use across all sub domains.

auth.domain.com
sub1.domain.com
sub2.domain.com
where if the user visits sub1.domain.com or sub2.domain.com and they are not logged in, they get pushed over to auth.domain.com and can log in. sub1.domain.com and sub2.domain.com are two separate applications but use the same credentials.

To solve this problem, we can use the code below::

$some_name = session_name("some_name");
session_set_cookie_params(0, '/', '.some_domain.com');
session_start();

No need to Change in php.ini file

 

Note:: If you find the better solution please comment below..

Leave a Comment