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?
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?
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
.