1. Use cookies to store session_id ();
Example: PHP code for a domain name file:
<? Phpsession_start (); setcookie ("session_id", session_id (), time () + 3600*24*365*10, "/", ".session.com "); $ _ session ['user _ name'] = 'liangshan Limin '; echo $ _ session ['user _ name'];?>
PHP code for domain name 2 file:
<?phpsession_destroy(); session_id($_COOKIE['session_id']);session_start();echo $_SESSION['user_name'];?>
2. use PHP. INI session. cookie_domain Note: you do not need to modify the PHP code here. ini configuration file; if necessary, you can. modify the configuration file in ini (in this case, you do not need to change the segment code: ini_set ("session. cookie_domain ", 'session. com ');) instance: domain name 1 file PHP code:
<? Phpini_set ("session. cookie_domain ", 'session. com '); // note: this parameter must be on sesson_start (); otherwise, session_start () will not take effect (); $ _ session ['user _ name'] = 'liangshan Limin '; echo $ _ session ['user _ name'];?>PHP code for domain name 2 file:
<?phpini_set("session.cookie_domain",'session.com');session_start();echo $_SESSION['user_name'];?>
In the future, we need to explain some problems!
1: ini_set ("session. cookie_domain", 'session. com '); it must be placed before session_start;
Second: You must note when testing some websites. Maybe you have no problem locally, but there is a problem on another machine or server, you need to check ha, ini_set ("session. cookie_domain ", 'session. com '); session.com must match your domain name! Otherwise, some of your session values will be faulty!
From: http://www.cnblogs.com/linzhenjie/archive/2013/01/23/2872541.html