Sharing php Session ($_SESSION) across multiple domain Sharing php Session ($_SESSION) across multiple domain codeigniter codeigniter

Sharing php Session ($_SESSION) across multiple domain


Considering your original question and your answers to Logan and myself in the comments of the original question I understand:

1 - you want to pass the session variables among a domain and its subdomains; and

2 - CI and Symfony load the session before you have a chance to do the ini_set command.

I believe you have two options:

1 - include the php configuration command in the php.ini file

session.cookie_domain=".foo.com"

If you try including it in the .htaccess it will not work if you are running php as a CGI module, which seems to be fairly common among shared hosting services.

2 - you can prepend a file to all php scripts in your site. Those will be put on top of every single php script your site runs, even the ones inside CI and Symfony. For example:

phpprepend.php file

<?phpini_set('session.cookie_domain', '.foo.com');?>

include the following line in your php.ini file:

auto_prepend_file = "/path/to/file/phpprepend.php"

Please let us know if this solves the problem.

Good luck!


Use session_name function let they have same session name. This will work for sub domains.And if they are complete different domains, and if you are using the cookie to pass session id, this will not work because cookie only work for one domain.


You need to set up the session cookie's domain so that it is accessible from both sites.

<?phpini_set('session.cookie_domain', '.foo.com');

Either add that to both sites's PHP code very early on in loading, or add something like this to your .htaccess file in both sites.

php_value session.cookie_domain ".foo.com"

I'm not 100% sure the second options works, but I think it should.