|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-12-26 21:00 UTC] k dot andris at gmail dot com
Description:
------------
The $_SESSION variable is empty when I look at it on a subdomain (abc.mydomain.com) even though session_id() is the same as on the main site (mydomain.com). Sessions are saved in files under /var/log/php5 - they just not read from there. The session cookie is OK too.
Reproduce code:
---------------
I have this on the base domain and on subdoamins too with different assigment lines. Still, they only seee their own assigments.
ini_set("session.cookie_domain", ".mydomain.net");
session_start();
print_r($_SESSION);
$_SESSION['main'] = 'main'; // assigment
print_r($_SESSION);
Expected result:
----------------
Since I have the same session id, I expect the $_SESSION variable to be shared acreoss pages, and subdomains.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 10:00:01 2025 UTC |
So on subdomains it does work all right. What clears the $_SESSION variable is the root domain. Session is passed fine between a.mysite.com and b.mysite.com, but if I open a session at mysite.com, it will not see the subdomain's session variables, and it will also erase them. The session cookie passes along fine. I call: ini_set('session.cookie_domain', '.mysite.com'); session_start(); I thought it does not work because the dot befor thee site's name (since the root does not have that dot), but removing it does not help either. Can you test this?I found it! The problem only occours if you serve the base domain and the subdomains from different sections of lighttpd config file, like this: $HTTP["host"] =~ "^mysite\.com" { server.document-root = "/var/www/mysite/" } $HTTP["host"] =~ "(.+)\.mysite\.com$" { server.document-root = "/var/www/mysubdomains/" }To "k dot andris at gmail dot com" You're right. Had exactly the same problem. Solution. Just add these 2 lines in your php.ini file: suhosin.session.cryptdocroot=Off suhosin.cookie.cryptdocroot=Off or, if you don't have access to it, these 2 in some of your general config.php file: ini_set("suhosin.session.cryptdocroot", "Off"); ini_set("suhosin.cookie.cryptdocroot", "Off");