访问域/子域之间的会话.本地xampp安装 [英] Accessing session between domain/subdomain. Local xampp installation
问题描述
提前致谢.
我在本地安装了 Xampp.我的网站设置如下.我有我的主域,即域"安装目录:C:\xampp\htdocs\domain
在此我有一个子域设置,即subdomain.domain
"安装目录:C:\xampp\htdocs\domain\subdomain
I have a local installation of Xampp. My sites are setup as follows. I have my main domain i.e. 'domain' installatiopn directory: C:\xampp\htdocs\domain
Within this i have a subdomain setup i.e. 'subdomain.domain
' installation directory: C:\xampp\htdocs\domain\subdomain
这样做的目的是在主域站点上进行单点登录,并且能够在用户访问子域站点时访问相同的会话数据(因此用户登录后不必重新进行身份验证)进入域门户网站).
The goal of this is to have a single sign on on the main domain site and be able to access the same session data when the user accesses the subdomain site (and thus not have to re-authenticate the user once they have logged into the domain portal site).
我在我的域 index.php 中创建会话如下:
I create the session in my domain index.php as follows:
session_set_cookie_params(0, '/', '.3pccap');
session_name('mysessionname');
session_start();
子域名 index.php
Subdomain index.php
session_name('mysessionname');
session_start();
我添加了一个 var_dump($_SESSION
);在每个 index.php 页面上确认哪些会话数据可用.一旦我登录到我的主域,会话就会填充用户数据.然后我导航到我的子域站点,该站点还运行会话变量的 var_dump.变量显示为空数组.
I've added a var_dump($_SESSION
); on each index.php page to confirm what session data is available. Once I log into my main domain, the session if populated with the users data. I then navigate to my subdomain site which also runs a var_dump of the session variable. The variable is displaying as an empty array.
我尝试在我的 php.ini 文件中设置会话 cookie 域,行为没有改变.
I have attempted setting the session cookie domain within my php.ini file, no change in behaviour.
非常感谢任何帮助.
推荐答案
您需要使 Session cookie 对您的子域可见(因此,在 both 上调用 session_set_cookie
、您的域和子域):
You need to make the Session cookie visible for your subdomain (thus, calling the session_set_cookie
on both, your domain and your subdomain):
session_set_cookie_params (0, '/', '.domain.com');
session_name('mysessionname');
session_start();
<小时>
编辑(来自评论,解决了问题)
EDIT (From comments, which solved the issue)
域主机名应该由两部分组成(即使对于本地开发),例如domain.local 而不是 domain
A domain hostname should consist of two parts (even for local development), e.g. domain.local instead of domain
这篇关于访问域/子域之间的会话.本地xampp安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!