“域”和“域”有什么区别?和“非域”曲奇饼?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 RFC2109:
因此,如果我理解正确的话,域 cookie 的域类似于
.y.com
,非域 cookie 的域类似于xycom
。域 cookie 对所有子域可见,非域 cookie 仅对其特定子域可见。当访问
www.y.com
和test.y.com
等子域时,带有域.y.com
的 cookie 可见(但不可见)y.com
),而域为xycom
的 cookie 仅在访问子域xycom
时可见,但在访问任何其他子域时不可见。From RFC2109:
So, if I understand it right, a domain cookie has a domain like
.y.com
and a non-domain cookie has a domain likex.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 likewww.y.com
andtest.y.com
(but noty.com
), while a cookie with the domainx.y.com
only is visible when visiting the subdomainx.y.com
but not any other subdomain.查看 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.
据我了解,非域 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.