共享同一主机上的域中的Cookie [英] sharing cookies across domains on same host
问题描述
我试图维护一个分布在同一主机的两个网域(一个实际上位于另一个的子文件夹)中的网站:
I'm trying to maintain a web site spread across two domains with the same host (one is actually in a subfolder of the other):
www.a.com -> /.../public_html/
www.b.com -> /.../public_html/b/
我在a.com上有一个脚本,我们称之为 public_html / readcookiedata.php
,它从cookie中读取一些会话变量。 b.com上的另一个脚本,让我们说 public_html / b / index.php
需要读取这个cookie。
I have one script on a.com, let's call it public_html/readcookiedata.php
, which reads in some session variables from a cookie. Another script on b.com, let's say public_html/b/index.php
, needs to also read this cookie.
现在 index.php
尝试 require_once(../ readcookiedata.php)
。
如果我访问 www.a.com/b/index.php
这个工作很好::cookie读取正确。
然而,如果我直接浏览到那里, www.b.com/index.php
,则不会读取cookie。
This works great if I visit www.a.com/b/index.php
: the cookie is read OK.
However, if I browse to there directly, www.b.com/index.php
, the cookie isn't read.
什么是解决这个问题的最佳方法? a.com有没有办法允许b.com读取其Cookie?
What's the best way to fix this problem? Is there a way for a.com to allow b.com to read its cookies? Or some way to configure the host to treat all requests to b.com as if they were for a.com/b/ instead?
推荐答案
或者某种方式配置主机以将所有请求处理为b.com
否。 Cookie安全性在浏览器级别内置到网络中;浏览器字面上不允许从其他网域的其他网域中读取Cookie的数据。
No. Cookie security is built into the web at a browser level; browsers literally won't allow you to read data for cookies from other domains on pages served by a different domain.
这篇关于共享同一主机上的域中的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!