跨子域和主机饼干 [英] Cookies across subdomains and hosts

查看:121
本文介绍了跨子域和主机饼干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我使用的开发环境和语言的组合编写应用程序,我需要访问一个单独的主机上从两个不同的子域,每一个cookie的。

In the application I'm writing using a combination of development environments and languages, I have need of accessing a cookie from two different subdomains, each on a separate host.

该Cookie正在使用PHP code后面设置 www.mydomain.com ,而我试图从<$ C $访问C> distant.mydomain.com 。

The cookie is being set on www.mydomain.com using the PHP code that follows, and I'm attempting to access it from distant.mydomain.com on a separate host.

setcookie('token', base64_encode(serialize($token)), time()+10800, '/', '.mydomain.com');

我想用下面的code来访问 distant.mydomain.com cookie的:

if (isset($_COOKIE['token'])) { /* do stuff */ }

问题: distant.mydomain.com 未找到该cookie 如果声明刚才提到返回false,即使cookie存在。

The problem: distant.mydomain.com is not finding the cookie. The if statement just mentioned returns false, even though the cookie exists.

我已经验证了所设置的Cookie是 mydomain.com (通过检查我的Firefox饼干)。我想不出任何理由,这将不工作。

I have verified that the cookie that is set is for mydomain.com (by checking my Firefox cookies). I can't think of any reason this wouldn't be working.

使用相同的的setcookie code,我只对 www.mydomain.com 主机,该应用程序能够跨域访问的cookie。这使我怀疑,这个问题有不同的主机做。

Using the same setcookie code, I have an old application running exclusively on the www.mydomain.com host, and that application is able to access the cookie across domains. This makes me suspect that the problem has to do with separate hosts.

万一以下任何信息是相关的:

- www.mydomain.com 是IIS 6.0

- distant.mydomain.com 就是Apache 2.2.9

- 两台服务器使用PHP 5.2.x

- 两台服务器在Windows Server上运行2003

Just in case any of the following information is pertinent:
- www.mydomain.com is IIS 6.0
- distant.mydomain.com is Apache 2.2.9
- Both servers use PHP 5.2.x
- Both servers are operating on Windows Server 2003

如果有任何进一步的信息,我可以为了更好地说明问题提供了,请让我知道!

If there is any further information I can provide in order to better describe the problem, please let me know!

推荐答案

有关任何阅读这个问题上的code和信息包含在原岗位的利益是完全正确的,做工精细。

For the benefit of anyone reading this question the code and information contained in the original post are exactly correct and work fine.

问题是,当你介绍其他的技术。例如,因为我已经了解到,通过一个Python模块,一个允许的Django服务PHP文件/内容发送PHP code,改变了什么是脚本访问一个很大的,什么不是。

The problem is when you introduce other technology. For instance, I have since learned that sending PHP code through a Python module, one that allows Django to serve PHP files/content, changes a great deal about what is accessible to the script and what is not.

这是最终发现以下马克Novakowski ,谁建议发送的咨询 $ _COOKIE为了找出什么在那里。到日志

This was eventually discovered following the advice of Marc Novakowski, who suggested sending $_COOKIE to the log in order to find out what was there.

我还检查了 $ _ SERVER $ _ GET 。这是 $空虚_ GET 的通风报信我送行,我尝试使用安装就没有那么简单,因为我原本以为。正是这种错误理解,导致不包括有关的Django在原岗位的信息。

I also checked out $_SERVER and $_GET. It was the emptiness of $_GET that tipped me off that the setup I am attempting to use is not as straightforward as I had thought. It was that mistaken understanding that led to not including the information about Django in the original post.

道歉的的感谢所有谁回答这个问题!

Apologies and thanks to all who responded to this question!

这篇关于跨子域和主机饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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