古怪的 cookie 行为
我的一位同事让我看一下 cookie 的一些行为。他创建了一个简单的 Web 应用程序,该应用程序创建了一个 cookie 并插入了文本字段的值,然后他检查了下一页上的 cookie 集合以查看它是否已插入并正确读回。
真的很简单。
然而,在第二页上,他指出这不仅仅是一个 cookie,其他 cookie 与他在本地调试的另一个网络应用程序相关。
我告诉他发生这种情况是因为浏览器识别了 URL,因此发送了它识别为来自那里的所有 cookie,这是正确的吗?即使本地调试服务器端口发生变化,它也会这样做吗?
A colleague of mine asked me to take a look at some cookie behaviour. He created simple web app that created a cookie and inserted the value of a text field, he then checked the cookie collection on the next page to see it had been inserted and read back correctly.
All simple really.
On the second page however he noted the was more than one cookie, with the others related to another web app he'd been debugging locally.
I told him this happened because the browser recognised the URL and hence sent all the cookies that it recognised as coming from there, is this correct? Would it do it even if the local debug servers port changed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cookie 基本上有两个参数,指示浏览器何时将它们发送回服务器:
如果没有给出
path
,则默认为文档位置,例如从http 设置的 cookie: //example.com/foo/bar.html
将被发送回所有以/foo
开头的 URL。如果
domain
以点开头,则它还涵盖所有子域。例如,为.example.com
设置的 cookie 也将被发送回static.example.com
。不考虑端口号。
调试 cookie 的问题不会影响您的访问者,只会影响开发人员,因此使用适当的浏览器选项删除 cookie 会更容易。
Cookies have basically two parameters that instruct the browser when to send them back to the server:
If no
path
is given, it defaults to the document location, e.g. a cookie set fromhttp://example.com/foo/bar.html
will be sent back to all URLs that begin with/foo
.If
domain
begins with a dot, it also covers all subdomains. E.g., a cookie set for.example.com
will also be sent back tostatic.example.com
.Port number is not considered.
The issue with debug cookies will not affect your visitors, only developers, so it's easier to just remove the cookies with the appropriate browser option.