如何在Rails中的单独的域上设置cookie [英] How to set a cookie on a separate domain in Rails

查看:125
本文介绍了如何在Rails中的单独的域上设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用javascript通话呼叫我的网站的其他网域上设定Cookie?它在FF3中工作,但不在IE6中。



我的服务器是从单独的站点和域的javascript标签调用的。结果返回javascript,用数据填充他们的页面(它是一个小部件)。我试图设置一个cookie使用domain =。mydomain.com和path =/。它适用于Firefox,但不会在IE中工作。如果我测试从我自己的域的javascript调用,它在IE中工作。



有谁知道如何获取跨域cookie设置在IE中使用Rails? / p>

解决方案

只要您的服务器在自己的域或域的子域中设置cookie, p>

  cookies [cookie_name] = {
:value => 'a value',
:expires => 1.year.from_now,
:domain => 'example.com'
}

它不适用于任何其他域。 / p>

要使其在IE6中正常工作,您可能需要有效的 P3P policy header



这样发送的标题应该是:

  headers [p3p] ='CP =CAO PSA OUR'


How can you set a cookie on a different Domain that is calling my site with a javascript call? It works in FF3, but not in IE6.

My server is called from a javascript tag on a seperate site and domain. The result returns javascript that populates their page with data (it's a widget). I am trying to set a cookie using domain=".mydomain.com" and path="/". It works for Firefox, but won't work in IE. It works fine in IE if I test the javascript call from my own domain.

Does anyone know how to get cross domain cookie setting to work in IE, using Rails?

解决方案

As long as your server is setting a cookie within its own domain or from a subdomain of its domain, this should work

cookies[cookie_name] = {
   :value => 'a value',
   :expires => 1.year.from_now,
   :domain => 'example.com'
 }

It won't work for any other domains.

To get this to work in IE6 you may need a valid P3P policy header

Something like this sent as a header should do it:

headers["p3p"] = 'CP="CAO PSA OUR"'

这篇关于如何在Rails中的单独的域上设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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