Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to share cookies between subdomains

Is it possible to share cookies between the following subdomains??

sharepoint.server.com   AND     data.server.com
like image 500
vlcod Avatar asked Sep 02 '15 13:09

vlcod


People also ask

Can subdomain read cookie?

The cookie's value can be read or written from all subdomains.

Can subdomain set cookie for another subdomain?

Please everyone note that you can set a cookie from a subdomain on a domain. But you CAN'T set a cookie from a domain on a subdomain.

Can you share cookies across domains?

Cookies are small pieces of data that are stored on your computer when you visit a website. Cookies are used to remember your preferences and to track your behavior on the website. You can share cookies across domains by setting the domain attribute of the cookie.

Can subdomain access parent domain cookies?

If a cookie is scoped to a parent domain, then that cookie will be accessible by the parent domain and also by any other subdomains of the parent domain.


1 Answers

You can specify the cookie's domain in your header

Set-Cookie: name=value; domain=.mydomain.com

the . in front of the URL makes the cookie available throughout any subdomain.


In RFC 2109, a domain without a leading dot meant that it could not be used on subdomains, and only a leading dot (.mydomain.com) would allow it to be used across subdomains.

source and more details


UPDATE

According to MDN, leading dots are no longer required to include subdomains. Subdomains are now included within the domain declaration.

like image 126
Jeff Noel Avatar answered Oct 11 '22 01:10

Jeff Noel