简体   繁体   English

阻止PHP发送带有请求的PHPSESSID cookie?

[英]Prevent PHP from sending the PHPSESSID cookie with requests?

I am serving dynamic image content which is generated by PHP. 我正在提供由PHP生成的动态图像内容。 But for such requests to a .php file, the PHPSESSID cookie is being sent along, which is a waste. 但是对于此类对.php文件的请求,PHPSESSID cookie会被发送出去,这很浪费。

Is it possible to prevent PHP from sending this cookie with requests to a PHP file? 是否可以防止PHP将包含请求的cookie发送到PHP文件? Or is it completely necessary for PHP to work? 还是完全需要PHP起作用?

Thanks for your time! 谢谢你的时间!

The browser will send any cookie that applies to a certain path-domain combination. 浏览器将发送适用于特定路径域组合的任何cookie。 You have no control over that, except using different paths and domains. 您无法对此进行控制,除非使用不同的路径和域。 This is why many sites use static content domains . 这就是为什么许多站点使用静态内容域的原因

This is used by PHP's session functions. 这由PHP的会话函数使用。 If your site doesn't use sessions, then this probably shouldn't be showing up. 如果您的站点不使用会话,则可能不应该显示该会话。

Keep in mind that the cookie is sent by the browser and you have no control over its transmission. 请记住,cookie是由浏览器发送的,您无法控制其传输。

you're saying "dont use cookies for sessions, use a phpsessid as a get parameter" php deprecated this for a reason. 您说的是“不要在会话中使用cookie,请使用phpsessid作为get参数” php弃用了一个原因。 Cookies will always be sent to the same domain. Cookies将始终发送到同一域。 If you really want to avoid the MINIMAL overhead, resources which dont need cookies should be in a separate domain, thus the cookie wont be sent. 如果您确实想避免最小的开销,则不需要cookie的资源应位于单独的域中,因此将不发送cookie。 IE. IE浏览器 static.domain.com for static content. static.domain.com的静态内容。 It's not worth the hassle, honestly. 老实说,这不值得麻烦。

i've searched and this is the only solution i found that worked for me. 我已经搜索过,这是我发现对我有用的唯一解决方案。

Add the following code to your .htaccess file: 将以下代码添加到您的.htaccess文件中:

RewriteCond %{QUERY_STRING} PHPSESSID=.*$ RewriteCond%{QUERY_STRING} PHPSESSID =。* $

RewriteRule .* %{REQUEST_URI}? RewriteRule。*%{REQUEST_URI}? [R=301,L] [R = 301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM