7

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

sharepoint.server.com   AND     data.server.com
vlcod
  • 189
  • 1
  • 2
  • 12
  • 1
    possible duplicate of [Share cookie between subdomain and domain](http://stackoverflow.com/questions/18492576/share-cookie-between-subdomain-and-domain) – Jeff Noel Sep 02 '15 at 13:50

1 Answers1

8

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.

Community
  • 1
  • 1
Jeff Noel
  • 6,972
  • 3
  • 35
  • 63
  • 1
    What if the subdomains want to share the session between them, but not with the www subdomain? Haven't found a way at the moment :( – xarlymg89 Jan 08 '16 at 16:44
  • 1
    Looks like this is no longer true. MDN says "Contrary to earlier specifications, leading dots in domain names are ignored. If a domain is specified, subdomains are always included." -- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#Directives – Qwertie Nov 02 '17 at 02:35