Zack
Zack

Reputation: 1287

How to set a cookie on a separate domain in Rails

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?

Upvotes: 10

Views: 11691

Answers (1)

DanSingerman
DanSingerman

Reputation: 36532

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

Upvotes: 15

Related Questions