Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 719
Zack Avatar asked Mar 24 '09 18:03

Zack


1 Answers

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"'
like image 135
DanSingerman Avatar answered Nov 14 '22 22:11

DanSingerman