# Cross domain cookie

**URL:** <https://www.ruby-forum.com/t/cross-domain-cookie/141270>\
**Category:** Rails\
**Created:** [June 24, 2008, 8:10am UTC](https://www.ruby-forum.com/t/cross-domain-cookie/141270 "2008-06-24T08:10:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unni123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/94ad74/32.png) [@unni123](https://www.ruby-forum.com/u/unni123)\
**Post date:** [June 24, 2008, 8:10am UTC](https://www.ruby-forum.com/t/cross-domain-cookie/141270/1 "2008-06-24T08:10:49Z")

</div>

My rails server runs on localhost. I want to set a cookie for the  
domain “.myapp.com”. How do I do this?

(i tried cookies['xyz] = {:value =\> ‘abc’ ,:domain =\> ‘.myapp.com’} .  
It doesnt work. No cookie is being set when i specify domain like  
that.

thanks in advance.

---

<div class="post-metadata">

**Author:** ![unni123](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/94ad74/32.png) [@unni123](https://www.ruby-forum.com/u/unni123)\
**Post date:** [June 24, 2008, 11:23am UTC](https://www.ruby-forum.com/t/cross-domain-cookie/141270/2 "2008-06-24T11:23:52Z")

</div>

On Jun 24, 7:10 am, Unni [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> My rails server runs on localhost. I want to set a cookie for the  
> domain “.myapp.com”. How do I do this?

You can only set the domain to a parent of the website serving the  
request (so if the browser accesses the website as [foo.bar.com](http://foo.bar.com) then  
you can set a cookie for [foo.bar.com](http://foo.bar.com) or [bar.com](http://bar.com)). Apart from that I’ve  
set cookies in exactly the way you show.

Fred
