跨子域名PHP会议 [英] PHP Sessions across sub domains
问题描述
我试图建立以下内容:
auth.domain.com
sub1.domain.com
sub2.domain.com
其中,如果用户访问sub1.domain.com或sub2.domain.com,他们还没有登录,他们将被推到auth.domain.com,可以登录。sub1.domain.com和sub2.domain .COM是两个独立的应用程序,但使用相同的凭据。
where if the user visits sub1.domain.com or sub2.domain.com and they are not logged in, they get pushed over to auth.domain.com and can log in. sub1.domain.com and sub2.domain.com are two separate applications but use the same credentials.
我试着设置在我的php.ini以下内容:
I tried setting the following in my php.ini:
session.cookie_domain = ".domain.com"
但它似乎并没有从一个域传递信息给对方。
but it doesn't seem to be passing the information from one domain to the other.
我试过如下:
sub1.domain.com/test.php
sub1.domain.com/test.php
session_set_cookie_params(0, '/', '.domain.com');
session_start();
print session_id() . "<br>";
$_SESSION['Regsitered'] = 1;
echo '<a href="http://auth.domain.com/test.php">Change Sites</a>'
auth.domain.com/test.php
auth.domain.com/test.php
session_set_cookie_params(0, '/', '.domain.com');
session_start();
print session_id() . "<br>";
$_SESSION['Checked'] = 1;
print_r($_SESSION);
的会话ID是完全一样的,但是当我倾倒了$ _SESSION变量不显示这两个键,就不管我重点每个域下设。
The session IDs are exactly the same but when I dump out the $_SESSION variable it doesn't show both keys, just whatever key I set under each domain.
我更新
推荐答案
我不知道,如果问题仍然存在,但我只是碰到了同样的问题,解决它调用session_set_cookie_params()之前设置一个会话名称:
I don´t know if the problem still exists, but I just ran into the same problem and solved it setting a session name before calling session_set_cookie_params():
$some_name = session_name("some_name");
session_set_cookie_params(0, '/', '.some_domain.com');
session_start();
我在我的php.ini什么也没有改变,但现在一切工作正常。
I have changed nothing in my php.ini but now everything is working fine.
这篇关于跨子域名PHP会议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!