“域”和“域”有什么区别?和“非域”曲奇饼?

发布于 2024-08-09 21:07:08 字数 218 浏览 4 评论 0原文

I'm reading the MDC entry for nsICookieManager2.add and it talks about domain and non-domain cookies. What are the differences between the two types of cookies?

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

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

发布评论

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

评论(3

拍不死你 2024-08-16 21:07:08

来自 RFC2109:

主机 A 的名称域与主机 B 的名称域匹配
if [...] A 是 FQDN 字符串并且具有
形式 NB,其中 N 是非空
名称字符串,B 的形式为 .B',并且
B' 是 FQDN 字符串。 (所以,xycom
域名匹配 .y.com,但不匹配 y.com。)

因此,如果我理解正确的话,域 cookie 的域类似于 .y.com,非域 cookie 的域类似于xycom。域 cookie 对所有子域可见,非域 cookie 仅对其特定子域可见。

当访问 www.y.comtest.y.com 等子域时,带有域 .y.com 的 cookie 可见(但不可见) y.com),而域为 xycom 的 cookie 仅在访问子域 xycom 时可见,但在访问任何其他子域时不可见。

From RFC2109:

Host A's name domain-matches host B's
if [...] A is a FQDN string and has
the form NB, where N is a non-empty
name string, B has the form .B', and
B' is a FQDN string. (So, x.y.com
domain-matches .y.com but not y.com.)

So, if I understand it right, a domain cookie has a domain like .y.com and a non-domain cookie has a domain like x.y.com. A domain cookie is visible for all subdomains, and non-domain cookie is only visible for it's specific subdomain.

A cookie with the domain .y.com is visible when visiting subdomains like www.y.com and test.y.com (but not y.com), while a cookie with the domain x.y.com only is visible when visiting the subdomain x.y.com but not any other subdomain.

忆依然 2024-08-16 21:07:08

查看 RFC,如果创建 cookie 时未指定域,则将应用请求主机的域。因此,来自 www.foo.com 且未指定域的请求将在域中包含 www.foo.com。

但是,您可能希望显式设置域以在各个子域中使用 cookie。将 cookie 域设置为 foo.com 将允许您在 www.foo.com 或 help.foo.com 或 *.foo.com 上访问它。当在您可能托管的应用程序周围传递某些状态时,这非常有用。

Looking at the RFC, if the domain is not specified when the cookie is created, the domain from the requesting host will be applied. So a request from www.foo.com without a domain specified will have www.foo.com in the domain.

However, you may wish to explicitly set the domain to use the cookie across a variety of sub-domains. Setting the cookie domain to foo.com will allow you to access it on www.foo.com or help.foo.com or *.foo.com. This comes in very useful when passing some state around applications you maybe hosting.

相权↑美人 2024-08-16 21:07:08

据我了解,非域 cookie 没有任何意义。 Cookie 始终与域绑定,并且只有该域的 Cookie 才会传递到应用程序并可以使用。但是,是的,我们可以通过一些技术来创建跨域 cookie。这是一个解释这一点的教程。我不知道您的项目是否使用 php,因为本教程使用 php 解释了这个概念。

http://www.tutorialized.com/view /tutorial/Implementing-Cross-Domain-Cookies/372

希望这有帮助。

As far as i understand a non-domain cookie makes no sense. Cookies are always tied to a domain and only the cookies for that domain gets passed to the application and can be used. But yes there are techniques by which we can create cross domain cookies. Here is a tutorial that explains this. I don't know if you are using php for your project, because this tutorial explains the concept using php.

http://www.tutorialized.com/view/tutorial/Implementing-Cross-Domain-Cookies/372

Hope this helps.

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