http - subdomain.example.com 是否可以设置 example.com 可以读取的 cookie?

标签 http cookies subdomain

我简直无法相信这是如此难以确定。

即使阅读了 RFC,我也不清楚 subdomain.example.com 的服务器是否可以设置 example.com 可以读取的 cookie。

subdomain.example.com可以设置Domain属性为.example.com的cookie。 RFC 2965 似乎明确声明这样的 cookie 不会发送到 example.com,但同样表示如果您设置 Domain=example.com,则会在前面加上一个点,就好像您说的是 .example.com 一样。总而言之,这似乎是说如果 example.com 返回设置了一个 Domain=example.com 的 cookie,它不会取回该 cookie!这是不对的。

谁能解释一下这些规则到底是什么?

最佳答案

是的。

如果您确保指定域是.example.com,那么*.example.com 和example.com 就可以访问它。

正是这个原则允许网站在有人访问 www.website.com 时发出 cookie。在有人离开 www 并转到 website.com 时访问 cookie。

编辑:来自关于 cookie 的 PHP 文档:

domain The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the » spec for details. http://php.net/manual/en/function.setcookie.php

而且它不是 PHP 独有的。

关于http - subdomain.example.com 是否可以设置 example.com 可以读取的 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3089199/

相关文章:

基于 Http 的 Linux 服务器状态 API

javascript - Chrome 扩展 - cookies.getAll 不返回任何内容

javascript - 如何以编程方式获取 Google Analytics 中当前访问的事件/来源/媒介

ios - 如何清除 iOS 中特定域的 cookie?

子域无法在 WHM 控制面板上运行

php - header ("Expires: 0") 是做什么的?

php - 采埃孚 : http request from one controller to onther hangs

cookies - 子域cookie安全

php - Symfony2 : Transparent authorization process between subdomains

Python请求参数/处理api分页