1

I have 2 subdomains sub1.domain.com and sub2.domain.com

sub1 is the one to set the login session but the session was not shared because they have different cookie domain

sub1's cookie domain => .sub1.domain.com

sub2's cookie domain => .sub2.domain.com

Option 1: to change sub2's .sub2.domain.com into .sub1.domain.com so that they can share session

Option 2: to change sub1's .sub1.domain.com to .domain.com

I would want the option 1 because we're trying to avoid changes on sub1.domain.com and domain.com as possible.

I have tried this codes on sub2's end but no luck

ini_set('session.cookie_domain', '.sub1.domain.com');
session_set_cookie_params (0,'/','.sub1.domain.com');
J.K
  • 1,382
  • 1
  • 11
  • 27
zivklen
  • 79
  • 2
  • 10
  • You [cannot set cookies for another domain](http://stackoverflow.com/questions/6761415/how-to-set-a-cookie-for-another-domain). However I see no reason option 2 would not work. – Matt Raines Apr 22 '16 at 09:34
  • You cannot set cookies for a *different* domain, but you can set cookies for a higher-level domain, which would work here. – Kevin Borders Aug 14 '16 at 16:42

1 Answers1

3

You cannot set session.cookie_domain to a different subdomain, but you can set it to .domain.com and it will be visible on all subdomains:

ini_set('session.cookie_domain', '.domain.com');
Kevin Borders
  • 2,933
  • 27
  • 32