删除 X-Powered-By

发布于 2024-08-28 23:21:45 字数 252 浏览 2 评论 0原文

  1. 如何删除 PHP 中的 X-Powered-By 标头?我在 Apache 服务器上,使用 php 5.21。 我无法在 php 中使用 header_remove 函数,因为 5.21 不支持它。我使用了 Header unset X-Powered-By,它在我的本地计算机上工作,但在我的生产服务器上不起作用。

  2. 如果 php 不支持 header_remove() 版本

    5.3,有替代方案吗?

  1. How can I remove X-Powered-By header in PHP? I am on an Apache Server and I use php 5.21.
    I can't use the header_remove function in php as it's not supported by 5.21. I used Header unset X-Powered-By, it worked on my local machine, but not on my production server.

  2. If php doesn't support header_remove() for ver < 5.3, is there an alternative?

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

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

发布评论

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

评论(9

玩心态 2024-09-04 23:21:45

我认为这是由 PHP.ini< 中的 expose_php 设置控制的/a>:

expose_php = off

决定 PHP 是否可以公开它安装在服务器上的事实(例如,通过将其签名添加到 Web 服务器标头)。它无论如何都不构成安全威胁,但它可以确定您是否在服务器上使用 PHP。

不存在直接的安全风险,但正如 David C 指出的那样,暴露过时(且可能存在漏洞)的 PHP 版本可能会邀请人们尝试攻击它。

I think that is controlled by the expose_php setting in PHP.ini:

expose_php = off

Decides whether PHP may expose the fact that it is installed on the server (e.g. by adding its signature to the Web server header). It is no security threat in any way, but it makes it possible to determine whether you use PHP on your server or not.

There is no direct security risk, but as David C notes, exposing an outdated (and possibly vulnerable) version of PHP may be an invitation for people to try and attack it.

可是我不能没有你 2024-09-04 23:21:45

If you cannot disable the expose_php directive to mute PHP’s talkativeness (requires access to the php.ini), you could use Apache’s Header directive to remove the header field:

Header unset X-Powered-By
何其悲哀 2024-09-04 23:21:45
if (function_exists('header_remove')) {
    header_remove('X-Powered-By'); // PHP 5.3+
} else {
    @ini_set('expose_php', 'off');
}
if (function_exists('header_remove')) {
    header_remove('X-Powered-By'); // PHP 5.3+
} else {
    @ini_set('expose_php', 'off');
}
凯凯我们等你回来 2024-09-04 23:21:45

如果您有权访问 php.ini,请设置 expose_php = Off

If you have an access to php.ini, set expose_php = Off.

美人迟暮 2024-09-04 23:21:45

尝试在发送标头之前添加 header() 调用,例如:

header('X-Powered-By: Our company\'s development team');

无论 php.ini 中的 hide_php 设置如何

Try adding a header() call before sending headers, like:

header('X-Powered-By: Our company\'s development team');

regardless of the expose_php setting in php.ini

坦然微笑 2024-09-04 23:21:45

如果您使用 FastCGI 尝试:

fastcgi_hide_header X-Powered-By;

If you use FastCGI try:

fastcgi_hide_header X-Powered-By;
筑梦 2024-09-04 23:21:45

要隐藏 X-Powered-By: PHP/7.xx ,如果您使用共享主机、VPS、云服务器,则在 .htaccess 文件中添加以下代码

Header always unset X-Powered-By
Header unset X-Powered-By

适用于:Wordpress、Codeigniter、Laravel、Php

To hide X-Powered-By: PHP/7.x.x , if you are using Share Hosting, VPS, Cloud Server then add the following code in .htaccess file

Header always unset X-Powered-By
Header unset X-Powered-By

Work well for: Wordpress, Codeigniter, Laravel, Php

苦笑流年记忆 2024-09-04 23:21:45

这个解决方案对我有用:)

请在脚本中添加以下行并检查。

可能不需要 Ngnix / Apache 等级别设置。

header("Server:");

This solution worked for me :)

Please add below line in the script and check.

Ngnix / Apache etc level settings might not be required.

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