古怪的 cookie 行为

发布于 2024-09-29 07:16:15 字数 285 浏览 0 评论 0原文

我的一位同事让我看一下 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 技术交流群。

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

发布评论

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

评论(1

怂人 2024-10-06 07:16:15

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:

  • path
  • domain

If no path is given, it defaults to the document location, e.g. a cookie set from http://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 to static.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.

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