I am trying to set up the following:
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.
I tried setting the following in my php.ini:
session.cookie_domain = ".domain.com"
but it doesn't seem to be passing the information from one domain to the other.
[Edit]
I tried the following:
sub1.domain.com/test.php
session_set_cookie_params(0, '/', '.domain.com');
session_start();
print session_id() . "<br>";
$_SESSION['Regsitered'] = 1;
echo '<a href="http://auth.domain.com/test.php">Change Sites</a>'
auth.domain.com/test.php
session_set_cookie_params(0, '/', '.domain.com');
session_start();
print session_id() . "<br>";
$_SESSION['Checked'] = 1;
print_r($_SESSION);
The session IDs are exactly the same but when I dump out the $_SESSION variable it doesn't show both keys, just whatever key I set under each domain.
[Edit 2]
I updated [Edit]
Simply try using following code just above
session_start()
methodI don´t know if the problem still exists, but I just ran into the same problem and solved it setting a session name before calling session_set_cookie_params():
I have changed nothing in my php.ini but now everything is working fine.
Use this , it works:
I know this is old but this works fine for me with multiple domains and sub domains on the same box.
?>
Use it on every domain/subdomain:
Path for
session.save_path
can be different for your case but it should be the same on every domain/subdomain. It is not always true by default.I solved it like this
Because I was working on localhost
wasn't working, it sees .localhost as the toplevel instead of .com/.local/... (I suspect)
I also used .dev because working on OS X doesn't seem to resolve .com as first in HOSTS