Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to share a cookie between a domain and a subsubdomain

I'm trying to share a cookie between www.example.com and admin.other.example.com I've being able to make it work with other.example.com, but there's no way to access the sub-sub-domain

Edit: I handle subdomains by defining the cookie domain as .example.com (note the first dot)

like image 856
Maurizio Pozzobon Avatar asked Aug 26 '11 07:08

Maurizio Pozzobon


People also ask

Can cookies be shared between domains?

To share a cookie between domains, you will need two domains, for example myserver.com and slave.com . One of the domains will issue the cookies and the other domain will ask the first domain what cookie should be issued to the client.

Can you share cookies across subdomains?

To share cookies across subdomains, you can simply create cookies with the domain directive set to the parent domain, in this case, example.com, rather than either of the specific subdomains.

Can a cookie be shared?

Cookies are only accessible to a single domain that they are set to. I believe if you are using two sub-domains on the same domain it would be possible to share the cookies, however the browser doesn't send cookies set on one domain to any others. Edit: You also want to avoid storing large amounts of data in a cookie.

Are cookies specific to a domain?

The origin domain of a cookie is the domain of the originating request. If the origin domain is an IP, the cookie's domain attribute must not be set. If a cookie's domain attribute is not set, the cookie is only applicable to its origin domain.


1 Answers

You can only share cookies between a domain and its own subdomains. For example:

  • a cookie defined for the domain example.com can be accessed by www.example.com and foo.bar.example.com
  • a cookie defined for the domain www.example.com can be accessed by foo.www.example.com but not by bar.example.com
like image 97
Efran Cobisi Avatar answered Oct 07 '22 21:10

Efran Cobisi