0

I want to make a session on a subdomain, and then access it from my main domain. I have read many threads regarding the same problem but none of the answers works for me.

I have a VPS from Dreamhost, and i have sat the following line into phprc on both domains (phprc is added to php.ini, dreamhost way of editing php.ini) session.cookie_domain = ".MAINDOMAIN.com" where .MAINDOMAIN.com is reffering to my domain name. This was the working solution here: Sharing SESSION Variables Between Multiple Subdomains

I have then made a php file i call test.php on both login.DOMAIN.com and DOMAIN.com

On login.DOMAIN.com/test.php i have the following code:

session_start();
$_SESSION['test'] = "Works";
print_r($_SESSION);

The output when i navigate to the file:

Array ( [test] => Works )

After visiting that page I Then go to DOMAIN.com/test.php where the code is:

session_start();
print_r($_SESSION);

And the output is:

Array ( )

I have seen other threads like this: Allow php sessions to carry over to subdomains with 4 diffrent options to set the php.ini line (Directly in php.ini, in .htaccess, in the script, and finally php-fpm pool configuration) and i have tried them all with the exception of the last one with php-fpm pool configuration

I have also tried to set this line on top of my php files, before session_start:

session_set_cookie_params(0,"/",".MAINDOMAIN.com",FALSE,FALSE);

And this on top of that:

session_name('mysession');

But nothing works

I have also checked with HTTP Header Live for FF wich domain the cookie is set for as the answer here: Why can't I pass user sessions between subdomains? and the string of Set-Cookie is:

Set-Cookie: PHPSESSID=9Q%2Cfrhr747fferf4700; path=/

There is no mention of what domain? What a'm i doing wrong? Any ideas?

2 Answers2

0

Maybe this is more of a work around but...

if you're not passing any private information you could pass the information from the sub domain to domain with $_GET's then use a page (getsession.php) on the domain to turn the $_GET's to $_SESSION's and redirect back to index of the domain to remove the $_GET's from url.

Sarpyjr
  • 179
  • 4
0

It is a limitation on Dremhost managed VPS, that don't allow sharing php sessions between virtual hosts (Subdomains). I have switched to another provider and everything works