问题
I am trying to use session data on multiple subdomains. Ej:
- www.mywebsite.com
- my.mywebsite.com
- test.mywebsite.com
- whateversub.mywebsite.com
When I try to use session data from www.mywebsite.com to any subdomain, all the session information is not accessible.
- I am NOT using cookies. Just sessions.
- I have godaddy as web host.
- Godaddy DOES allow to upload a custom php5.ini file
Since I am a php beginner, please dumb down your response so I may understand it.
Here is an example:
File 1:
<?php
//FILE 1: www.mywebsite/index.php
session_start();
$_SESSION['status'] = "ON";
header( 'Location: http://sub.mywebsite/' );
?>
File 2:
<?php
//FILE 2: sub.mywebsite/index.php
session_start();
echo "Your session status is: ";
echo $_SESSION['status'];
?>
回答1:
Be sure you set SESSIONID cookie on subdomain, too
ini_set('session.cookie_domain', '.my-domain.com');
回答2:
I solve my problem thanks to this link PHP Sessions across sub domains
PHP:
<?php
session_set_cookie_params(0, '/', '.mywebsite.com');
session_start();
//Code...
?>
回答3:
By default this will not work, but you can get around it as described here: http://www.gonnalearn.com/2008/04/10/sharing-session-data-across-domains-with-php/
来源:https://stackoverflow.com/questions/7324822/php-session-lost-on-subdomain