使用URL Frame重定向时Cookie失败 [英] Cookies fail when using URL Frame re-direct

查看:54
本文介绍了使用URL Frame重定向时Cookie失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的html文档,我已经在我的

(即)使用cookie的abc.com域上使用了一段时间。我最近购买了一个新的

域名并设置了一项服务,将我的新域名(即)

xyz.com重定向到abc.com域名的子目录。换句话说,当有人去URL xyz.com时,他们真的最终进入了abc.com/xyz

目录,但MSIE浏览器说它们是xyz.com 。


问题是当我在xyz.com现在的/ xyz子目录中复制

相同的HTML文档时,cookie退出此设置/>
访问。我不能再通过从JS调用

document.cookie函数来设置或获取cookie。通话不会失败

但数据始终为空白。我甚至尝试设置cookie并从

下一行代码立即读回来它仍然会

不保存cookie。


任何人都知道如何解决这个问题?


我检查了location.host,.hostname .pathname,

document.domain和他们的值所有表明我真的在abc.com甚至

虽然我的IE浏览器中的地址说我在xyz.com。

I have a simple html document I have been using for some time on my
(i.e.) abc.com domain that uses cookies. I recently purchased a new
domain name and set up a service to redirect my new domain (i.e.)
xyz.com to a sub-directory of the abc.com domain. In other words, when
someone goes to URL xyz.com, they really end up in abc.com/xyz
directory but the MSIE browser says they are xyz.com.

The problem is that cookies quit working in this setup when I copied
the same HTML document in the /xyz subdirectory that xyz.com now
accesses. I can''t set or get a cookie any longer by calling the
document.cookie function from JS any longer. The call does not fail
but the data is always blank. I even tried setting the cookie and from
the next line of code reading it back immediately and it still would
not save the cookie.

Anyone know how to fix this?

I checked the value of location.host, .hostname .pathname,
document.domain and they all indicate I am really at abc.com even
though the address in my IE browser says I am at xyz.com.

推荐答案

Don Juan写道:
Don Juan wrote:
我有一个简单的html文档,我已经在我的
(即)abc.com域上使用了一段时间使用cookies。我最近购买了一个新的域名,并设置了一项服务,将我的新域名(即)xyz.com重定向到abc.com域的子目录。换句话说,当有人去URL xyz.com时,他们真的最终会进入abc.com/xyz
目录,但MSIE浏览器说它们是xyz.com。


不要使用框架进行重定向。例如,使用服务器设置。

问题是当我在xyz.com的/ xyz子目录中复制相同的HTML文档时,cookie退出此设置工作
访问。我不能再通过从JS调用
document.cookie函数来设置或获取cookie了。呼叫不会失败
但数据始终为空白。


您无法读取或更改来自不同二级
域的Cookie。同源策略并不关心您拥有两个
二级域名;它们与它不同,并且访问被拒绝。

我甚至尝试设置cookie并从下一行代码读取它立即返回它仍然不会保存cookie。


但这很奇怪。您应该能够从同一站点设置,修改和读取该站点的

cookie。究竟你是怎么做到的?

我认为如果你发布了你的旧的URL,那将是最好的。域名。

任何人都知道如何解决这个问题?


可能。

我检查了location.host,.hostname .pathname,
document.domain的值,它们都表明我真的在abc.com甚至
虽然我的IE浏览器中的地址说我在xyz.com。
I have a simple html document I have been using for some time on my
(i.e.) abc.com domain that uses cookies. I recently purchased a new
domain name and set up a service to redirect my new domain (i.e.)
xyz.com to a sub-directory of the abc.com domain. In other words, when
someone goes to URL xyz.com, they really end up in abc.com/xyz
directory but the MSIE browser says they are xyz.com.
Do not use frames for redirection. Use server settings, for example.
The problem is that cookies quit working in this setup when I copied
the same HTML document in the /xyz subdirectory that xyz.com now
accesses. I can''t set or get a cookie any longer by calling the
document.cookie function from JS any longer. The call does not fail
but the data is always blank.
You cannot read or change cookies that are from a different second-level
domain. The Same Origin Policy does not care about that you own both
second-level domains; they are different to it, and access is denied.
I even tried setting the cookie and from the next line of code reading
it back immediately and it still would not save the cookie.
That is weird, though. You should be able to set, modify and read the
cookies for the site from the same site. Exactly how are you doing that?
I think it would be best if you posted the URL of your "old" domain.
Anyone know how to fix this?
Probably.
I checked the value of location.host, .hostname .pathname,
document.domain and they all indicate I am really at abc.com even
though the address in my IE browser says I am at xyz.com.




document.domain不表示任何内容。相反,您必须设置
document.domain才能从不同的
域访问文档或cookie,但是使用相同的二级域。

PointedEars



document.domain does not indicate anything. Instead, you have to _set_
document.domain in order to access documents or cookies from a different
domain, but the same second-level domain.
PointedEars


function createCookie(名称,价值,天数)

{

if(days)

{

var date = new Date();

date.setTime(date.getTime()+(days * 24 * 60 * 60 * 1000));

var expires =" ;; expires =" + date.toGMTString();

}

else var expires ="" ;;

document.cookie = name + QUOT; =" +值+期满+英寸; path = /" ;;

}


函数readCookie(名称)

{

var nameEQ = name +" =" ;;

var ca = document.cookie.split('';'');

for(var i = 0; i < ca.length; i ++)

{

var c = ca [i];

while(c.charAt(0)= ='''')c = c.substring(1,c.length);

if(c.indexOf(nameEQ)== 0)return

c。 substring(nameEQ.length,c.length);

}

返回null;

}

文件。写(''< br> location.href:''+ location.href)

document.write(''< br> location.protocol:''+

location.protocol)

document.write(''< br> location.host:''+ location.host)

document.write(''< ; br> location.hostname:''+

location.hostname)

document.write(''< br> location.pathname:''+

location.pathname)

document.write(''< br> docum ent.domain:''+ document.domain)

document.write(''< br> document.referrer''+

document.referrer)
document.write(''< br>读取cookie测试:''+

readCookie(" test"))

document.write( ''< br>设置Cookie测试:''+

createCookie(" test"," DVT",3))

document.write('' < br>读取Cookie测试:''+

readCookie(" test"))

function createCookie(name,value,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split('';'');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)=='' '') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return
c.substring(nameEQ.length,c.length);
}
return null;
}
document.write(''<br>location.href: '' + location.href)
document.write(''<br>location.protocol: '' +
location.protocol)
document.write(''<br>location.host: '' + location.host)
document.write(''<br>location.hostname: '' +
location.hostname)
document.write(''<br>location.pathname: '' +
location.pathname)
document.write(''<br>document.domain: '' + document.domain)
document.write(''<br>document.referrer '' +
document.referrer)
document.write(''<br>read cookie test: '' +
readCookie("test"))
document.write(''<br>set cookie test : '' +
createCookie("test","DVT",3))
document.write(''<br>read cookie test: '' +
readCookie("test"))


Don Juan写道:
Don Juan wrote:
[code]




您的代码,虽然它的效率不必要且格式错误,

在这里工作正常[1],前提是我在

`return''[2]之后删除了换行符。你要么包含换行符,要么返回

`undefined'',否则你不小心阻止了新的

站点的cookie访问。


如果您提到任何东西,那将是不错的(也是适当的)

[3]

PointedEars

___________

[1] Mozilla / 5.0(X11; U; Linux i686; en-US; rv:1.8.0.2)

Gecko / Debian-1.5.dfsg + 1.5.0.2- 2 Firefox / 1.5.0.2

[2]< URL:http://pointedears.de/scripts/test/dom/cookie-frameset>

(你会发现框架集并不重要。)


[3]< URL:http://jibbering.com/faq/faq_notes/pots1.html>

< URL:www.safalra.com/special/googlegroupsreply/>



Your code, although it is unnecessarily inefficient and badly formatted,
works fine here[1], provided that I remove the newline after the
`return''[2]. Either you have included the newline, thereby returning
`undefined'', or you have accidentally blocked cookie access for your new
site.

It would have been nice (and appropriate) if you had referred to anything
[3]
PointedEars
___________
[1] Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.2)
Gecko/Debian-1.5.dfsg+1.5.0.2-2 Firefox/1.5.0.2

[2] <URL:http://pointedears.de/scripts/test/dom/cookie-frameset>
(You will observe that the frameset does not matter.)

[3] <URL:http://jibbering.com/faq/faq_notes/pots1.html>
<URL:www.safalra.com/special/googlegroupsreply/>


这篇关于使用URL Frame重定向时Cookie失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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