阻止 PHP 通过请求发送 PHPSESSID cookie?

发布于 2024-09-01 00:00:31 字数 156 浏览 5 评论 0原文

我正在提供由 PHP 生成的动态图像内容。但对于此类对 .php 文件的请求,会同时发送 PHPSESSID cookie,这是一种浪费。

是否可以阻止 PHP 通过向 PHP 文件发送请求来发送此 cookie?或者 PHP 的工作完全有必要吗?

感谢您抽出时间!

I am serving dynamic image content which is generated by PHP. But for such requests to a .php file, the PHPSESSID cookie is being sent along, which is a waste.

Is it possible to prevent PHP from sending this cookie with requests to a PHP file? Or is it completely necessary for PHP to work?

Thanks for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

星星的軌跡 2024-09-08 00:00:31

浏览器将发送适用于特定路径域组合的任何 cookie。除了使用不同的路径和域之外,您无法控制这一点。这就是许多网站使用静态内容域的原因。

The browser will send any cookie that applies to a certain path-domain combination. You have no control over that, except using different paths and domains. This is why many sites use static content domains.

七七 2024-09-08 00:00:31

这是由 PHP 的会话函数使用的。如果您的网站不使用会话,那么这可能不应该显示。

请记住,cookie 是由浏览器发送的,您无法控制它的传输。

This is used by PHP's session functions. 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.

花开浅夏 2024-09-08 00:00:31

你是说“不要使用 cookie 进行会话,使用 phpsessid 作为获取参数”php 不赞成这样做是有原因的。
Cookie 将始终发送到同一域。如果你真的想避免最小开销,不需要cookie的资源应该位于单独的域中,这样cookie就不会被发送。 IE。 static.domain.com 用于静态内容。
老实说,这不值得这么麻烦。

you're saying "dont use cookies for sessions, use a phpsessid as a get parameter" php deprecated this for a reason.
Cookies will always be sent to the same domain. 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. IE. static.domain.com for static content.
It's not worth the hassle, honestly.

追星践月 2024-09-08 00:00:31

我已经搜索过了,这是我发现唯一对我有用的解决方案。

将以下代码添加到您的 .htaccess 文件中:

RewriteCond %{QUERY_STRING} PHPSESSID=.*$

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

i've searched and this is the only solution i found that worked for me.

Add the following code to your .htaccess file:

RewriteCond %{QUERY_STRING} PHPSESSID=.*$

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

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