如何设置仅对特定域(例如 example.com)有效但对其子域无效的 cookie?

发布于 2024-08-09 14:21:31 字数 164 浏览 4 评论 0原文

如果我有一个域 example.com,有什么方法可以使 cookie 仅对该特定域有效,而不对 www.example.com 等子域有效?

我知道我只能将其设置为 www.example.com,但它可以没有子域吗?

if I have a domain example.com, is there any way to make cookies valid only for that specific domain and not for sub-domains like www.example.com?

I know I can set it to only www.example.com, but can it be without a sub-domain?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被翻牌 2024-08-16 14:21:31

Cookie 通过名称、域和路径的组合来识别。因此,如果设置正确,您可以将其范围限制为特定域/子域和路径。

阅读 Wiki 的 HTTP Cookie 的属性部分
RFC2965

Cookies are identified by the combination of their name, domain, and path. So if set correctly, you can limit it's scope to a specific domain/sub-domain and path.

Read Wiki's HTTP Cookie's Attribute Section
or RFC2965

攒眉千度 2024-08-16 14:21:31

严格来说,带有限定符 ";domain=example.com" 的 cookie 对于“www.domain.com”域不应该可见。而 ";domain=.example.com" 对 www 主机可见。

不过我对此会非常警惕。我最近没有测试过这一点,但如果看到某些浏览器不符合这一点,我不会感到惊讶。

Strictly speaking a cookie carrying the qualifier ";domain=example.com" should not be visible to the "www.domain.com" domain. Whereas ";domain=.example.com" would be visible to the www host.

However I would be very wary of this. I haven't tested this recently but I wouldn't be surprised to see some browsers not conforming properly to this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文