为什么我不能在子域之间传递用户会话? [英] Why can't I pass user sessions between subdomains?

查看:111
本文介绍了为什么我不能在子域之间传递用户会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我使用了这篇SO文章中的所有建议的方法:
允许php会话转移到子域

First of all, I have used ALL of the suggested methods in this SO article: Allow php sessions to carry over to subdomains

为方便起见,以下是我已经遵循的提示:

For your convenience, here are the tips I already followed:


这里有3个选项。

Here are 3 options.

将它放在您的php.ini中:

Place this in your php.ini:

session.cookie_domain = ".example.com"

在您的.htaccess中:

In your .htaccess:

php_value session.cookie_domain .example.com

作为脚本中的第一件事:

As the first thing in your script:

ini_set('session.cookie_domain','.example.com' );


我有9个子域名(losangeles.mysite.com,sandiego.mysite.com等),我希望用户能够在他们之间保持登录。然而,到目前为止,服务器正在将每个子域作为一个完全包含的网站,并且单独的会话。

I have 9 subdomains (losangeles.mysite.com, sandiego.mysite.com, etc), and I would like users to be able to stay signed in between them. As of now, however, the server is treating each subdomain as a fully contained site with separate sessions.

还有什么我可以做吗?

Is there anything else I can do? Or how can I troubleshoot this?

推荐答案

我怀疑正在为.foo.example.com而不是.example设置Cookie .com。尝试安装Firefox的Live HTTP Headers插件,并检查Cookie被设置为什么。

I suspect the cookies are being set for .foo.example.com instead of .example.com. Try installing the Live HTTP Headers add-on for Firefox and checking what the cookies are getting set as.

要执行此操作,打开Live HTTP Headers并打开窗口,转到设置Cookie的页面。在窗口中,应该有一条看起来像这样的线。

To do this, open Live HTTP Headers and with the window open, go to the page that sets the cookie. In the window, there should be a line that looks like this.

Set-Cookie:lng = en-US; path = /; domain = .example.com;

Set-Cookie: lng=en-US; path=/; domain=.example.com;

如果cookie设置为domain = .foo.example.com;那么你知道什么问题是。但是,如果域名是.example.com,则还会发生其他情况。

If the cookie is set for domain=.foo.example.com; then you know what the problem is. However, if the domain is .example.com, something else is going on.

此外,如果在foo.example上为.example.com设置了Cookie。 com,请检查浏览器是否正在向bar.example.com发送Cookie。这应该有助于找出问题所在。

Also, if the cookies are getting set for .example.com on foo.example.com, check to see if the browser is sending cookies to bar.example.com. This should help track down where the problem is.

这篇关于为什么我不能在子域之间传递用户会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆