Apache / PHP 禁用子域的 Cookies?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1165831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache / PHP Disable Cookies for Subdomain?
提问by stukerr
I am trying to follow these guidelinesto make my page load quicker.
我正在尝试遵循这些准则以使我的页面加载速度更快。
I have created a static subdomain to load static content from, however it is advising me to not have cookies sent on this subdomain, any ideas on how I might be able to do this in Apache/PHP?
我已经创建了一个静态子域来从中加载静态内容,但是它建议我不要在这个子域上发送 cookie,关于如何在 Apache/PHP 中执行此操作的任何想法?
I've searched around and come up with nothing yet.
我已经四处搜索,但一无所获。
采纳答案by Tyler Carter
If you never explicitly set a cookie, cookies won't be present on the server. So, if you are using the second domain simply as a repository for images or CSS files, most likely no cookies are ever set.
如果您从未明确设置 cookie,则服务器上将不会出现 cookie。因此,如果您仅将第二个域用作图像或 CSS 文件的存储库,则很可能没有设置 cookie。
Updated from Comments.
从评论更新。
If you see a 'Request' cookie header to a subdomain you don't want to have cookies, clear your cookies and see if the server ever sends a cookie header in the Response headers. If it does, it is possible you have session.auto_start enabled, or you have a script that sets cookies.
如果您看到一个“请求”cookie 标头指向您不想拥有 cookie 的子域,请清除您的 cookie 并查看服务器是否曾在响应标头中发送过 cookie 标头。如果是这样,则可能是您启用了 session.auto_start,或者您有设置 cookie 的脚本。
You can check the Request and Response Headers using something like Firebug with Google Page Speed.
您可以使用 Firebug 和 Google Page Speed 之类的工具检查请求和响应标头。
回答by Brad Gignac
You can easily take care of this in PHP. When you set your cookie, the parameter that needs to be set is the domain parameter. Often, this is set to ".domain.com" to make it available on any subdomain. Instead, you might try setting it to "www.domain.com" to restrict it to that domain. Check out the PHP manual's setcookie() documentation.
您可以在 PHP 中轻松解决这个问题。设置cookie时,需要设置的参数是域参数。通常,这被设置为“.domain.com”以使其在任何子域上可用。相反,您可以尝试将其设置为“www.domain.com”以将其限制为该域。查看 PHP 手册的setcookie() 文档。

