简体   繁体   English

无法在子域和主域之间共享PHP会话

[英]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.

相关问题 与主域共享会话到子域Codeigniter - Share Sessions with Main Domain to Subdomain Codeigniter 我可以使用php Sessions在多个客户端之间共享Session变量吗? - Can I share Session variables between multiple clients with php Sessions? PHP / Laravel:跨每个域的子域共享会话 - PHP / Laravel: Share sessions across subdomain of each domain 在IIS服务器上的.aspx和.php之间共享会话 - Share sessions between .aspx and .php on an IIS server 使用Redis作为会话存储时,如何在actix-session和PHP应用程序之间共享会话? - How can I share sessions between actix-session and a PHP application when using Redis as session storage? 如何在PHP和ASP.net应用程序之间共享会话? - How to share sessions between PHP and ASP.net application? Zend和纯PHP在同一域之间共享会话 - Share Sessions Between Zend and Pure PHP on Same Domain 是否可以在不同的PHP会话之间共享内存表? - Is it possible to share a memory table between different PHP sessions? 如何在Symfony控制器和经典独立php脚本之间共享会话数据,其中会话在memcache中管理? - How to share sessions data between Symfony controllers and classic stand alone php script where sessions are managed in memcache? php无法启动多个会话 - Php can't start multiple sessions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM