How to set a cookie on a separate domain in Rails

女生的网名这么多〃 提交于 2019-12-23 09:28:03

问题


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?


回答1:


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"'


来源:https://stackoverflow.com/questions/678628/how-to-set-a-cookie-on-a-separate-domain-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!