问题
I am trying to access session data across multiple wildcard sub domains. I set the session using the following:
<?php
session_name("session");
session_set_cookie_params(0, '/', '.example.com');
session_start();
$_SESSION['mID'] = 192;
?>
I set the above session while on sub1.example.com
. I then go to sub2.example.com
and use the following code to access the session:
<?php
session_name("session");
session_set_cookie_params(0, '/', '.example.com');
session_start();
print_r($_SESSION);
?>
But the session is empty. What am I missing?
回答1:
Have you tried using:
session_regenerate_id(true);
Worked for me when I have this problem.
http://php.net/manual/en/function.session-regenerate-id.php
来源:https://stackoverflow.com/questions/5458559/subdomain-session-issue