[英]Can't share PHP sessions between subdomain and main
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. 我有一个来自Dreamhost的VPS,并且在两个域中都将以下行放入phprc中(phprc已添加到php.ini中,这是编辑php.ini的dreamhost的方式)session.cookie_domain =“ .MAINDOMAIN.com”,其中.MAINDOMAIN。 com正在使用我的域名。 This was the working solution here: Sharing SESSION Variables Between Multiple Subdomains 这是这里的有效解决方案: 在多个子域之间共享SESSION变量
I have then made a php file i call test.php on both login.DOMAIN.com and DOMAIN.com 然后,我在login.DOMAIN.com和DOMAIN.com上都制作了一个名为test.php的php文件
On login.DOMAIN.com/test.php i have the following code: 在login.DOMAIN.com/test.php上,我具有以下代码:
session_start();
$_SESSION['test'] = "Works";
print_r($_SESSION);
The output when i navigate to the file: 当我导航到文件时的输出:
Array ( [test] => Works ) 数组([test] => Works)
After visiting that page I Then go to DOMAIN.com/test.php where the code is: 访问该页面后,我然后转到DOMAIN.com/test.php,其中的代码是:
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 我看到了这样的其他线程: 允许php会话通过4个不同选项传递到子域 ,以设置php.ini行(直接在php.ini中,.htaccess中,在脚本中,最后是php-fpm池配置)我已经尝试了所有这些,除了最后一个具有php-fpm池配置
I have also tried to set this line on top of my php files, before session_start: 在session_start之前,我还尝试将这行设置在我的php文件之上:
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? 我还检查了FF夹层域的HTTP Header Live的cookie设置为此处的答案: 为什么我不能在子域之间传递用户会话? and the string of Set-Cookie is: Set-Cookie的字符串是:
Set-Cookie: PHPSESSID=9Q%2Cfrhr747fferf4700; Set-Cookie:PHPSESSID = 9Q%2Cfrhr747fferf4700; path=/ 路径= /
There is no mention of what domain? 没有提到什么域名? What a'm i doing wrong? 我究竟做错了什么? Any ideas? 有任何想法吗?
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. 如果您不传递任何私人信息,则可以使用$ _GET将信息从子域传递到域,然后在域上使用页面(getsession.php)将$ _GET转换为$ _SESSION,然后重定向回索引域以从网址中删除$ _GET。
It is a limitation on Dremhost managed VPS, that don't allow sharing php sessions between virtual hosts (Subdomains). 这是对Dremhost管理的VPS的限制,不允许在虚拟主机(子域)之间共享php会话。 I have switched to another provider and everything works 我已切换到其他提供商,一切正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.