如果所有子域都指向同一个网站,cookie 是否会在多个子域之间共享?
Will the cookies be shared across multiple subdomains, if all subdomains point to the same single website?
我想创建一个网站,它可以根据子域表现不同。
如果我在子域 A 上设置了某个 cookie,我可以 read/access 在子域 C 上设置它吗?
或者 cookie 绑定到子域?
我建议您阅读这个问题 post,总而言之,它说重要的是您定义的用于设置 cookie 的域参数。你要找的是这样的东西 ".mydomain.com".
设置cookie时,有一个Domain
属性。这是来自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.
基本上,您只需要在Set-Cookie
中指定Domain
属性即可。
我想创建一个网站,它可以根据子域表现不同。
如果我在子域 A 上设置了某个 cookie,我可以 read/access 在子域 C 上设置它吗? 或者 cookie 绑定到子域?
我建议您阅读这个问题 post,总而言之,它说重要的是您定义的用于设置 cookie 的域参数。你要找的是这样的东西 ".mydomain.com".
设置cookie时,有一个Domain
属性。这是来自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.
基本上,您只需要在Set-Cookie
中指定Domain
属性即可。