I want to share my session variables in PHP using many subdomains. I have that example :
- example.com
- subdomain1.example.com
I try to use the same session variables between the two domains. I already tested a lot of functions in PHP but nothing work. Here is my way to test :
On the example.com/page.php, I have that test :
echo '<pre>';
var_dump(session_set_cookie_params(0, '/', '.example.com'));
session_start();
echo "Session ID : ".session_id()."\n";
$_SESSION['foo'] = 'bar';
print_r($_SESSION);
And on subdomain1.example.com/page.php, I have that one :
echo '<pre>';
session_set_cookie_params(0, '/', '.example.com');
session_start();
echo "Session ID : ".session_id()."\n";
print_r($_SESSION);
I can see that the session id is the same between the two pages, but session variables are impossible to read in subdomain1.example.com/page.php
I tested many functions, like set a name to the session, but with no more results.
Thank you.
The only way I can think of to do this would be to save the session data to a cookie, then open the cookie when the other domain is accessed. You can read how to do this here: http://www.depiction.net/tutorials/php/cookies-session-variables.php
Out of curiosity, why do you want to do this?