0

I would like to create website, which can behave differently based on subdomains.

If I set a certain cookie on subdomain A, can I read/access it on subdomain C? Or the cookie binds to the subdomain?

birdemic
  • 21
  • 1
  • 6

2 Answers2

2

I suggest you read this question post, in summary it says that what's important is the domain parameter you define to set the cookie. What your looking for is something like this ".mydomain.com".

Simon
  • 56
  • 6
2

When you set cookie, there is a Domain attribute. This is its explanation from MDN

Domain attribute The Domain attribute specifies which hosts can receive a cookie. If unspecified, the attribute defaults to the same host that set the cookie, excluding subdomains. If Domain is specified, then subdomains are always included. Therefore, specifying Domain is less restrictive than omitting it. However, it can be helpful when subdomains need to share information about a user.

For example, if you set Domain=mozilla.org, cookies are available on subdomains like developer.mozilla.org.

Basically, you just need to specify the Domain attribute in Set-Cookie.

sam
  • 1,767
  • 12
  • 15