php 删除 X-Powered-By
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2661799/
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
Removing X-Powered-By
提问by Castor
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.
If php doesn't support header_remove() for ver < 5.3, is there an alternative?
如何删除 PHP 中的 X-Powered-By 标头?我在 Apache 服务器上,我使用 php 5.21。我无法在 php 中使用 header_remove 函数,因为 5.21 不支持它。我使用了 Header unset X-Powered-By,它在我的本地机器上工作,但不在我的生产服务器上。
如果 php 不支持 ver < 5.3 的 header_remove(),是否有替代方法?
回答by Pekka
I think that is controlled by the expose_phpsetting in PHP.ini:
我认为这是由PHP.ini 中的expose_php设置控制的:
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.
决定 PHP 是否可以公开它安装在服务器上的事实(例如,通过将其签名添加到 Web 服务器标头)。它在任何方面都不是安全威胁,但可以确定您是否在服务器上使用 PHP。
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.
没有直接的安全风险,但正如 David C 指出的那样,暴露一个过时(并且可能存在漏洞)的 PHP 版本可能会邀请人们尝试攻击它。
回答by Pepper
header_remove("X-Powered-By");
回答by Gumbo
If you cannot disable the expose_phpdirectiveto mute PHP's talkativeness (requires access to the php.ini), you could use Apache's Headerdirectiveto remove the header field:
如果您无法禁用Expose_php指令来静音 PHP 的健谈性(需要访问php.ini),您可以使用Apache 的Header指令删除标头字段:
Header unset X-Powered-By
回答by luchaninov
if (function_exists('header_remove')) {
header_remove('X-Powered-By'); // PHP 5.3+
} else {
@ini_set('expose_php', 'off');
}
回答by Arseni Mourzenko
If you have an access to php.ini, set expose_php = Off.
如果您有权访问 php.ini,请设置expose_php = Off.
回答by Tinus Guichelaar
If you use FastCGI try:
如果您使用 FastCGI,请尝试:
fastcgi_hide_header X-Powered-By;
回答by Daniel Faure
Try adding a header() call before sending headers, like:
在发送标头之前尝试添加 header() 调用,例如:
header('X-Powered-By: Our company\'s development team');
regardless of the expose_php setting in php.ini
无论 php.ini 中的 Exposure_php 设置如何
回答by Walk
This solution worked for me :)
这个解决方案对我有用:)
Please add below line in the script and check.
请在脚本中添加以下行并检查。
Ngnix / Apache etc level settings might not be required.
可能不需要 Ngnix / Apache 等级别的设置。
header("Server:");

