php如何隐藏php的版本号(X-Powered-By: PHP)

作者

由php生成的html代码,默认会在 http协议的头部给出,php的版本号信息。处于安全的目的,需要把php的版本号给隐藏掉。删除php版本号,仅仅需要修改一个配置选择就可以。expose_php = On , expose 顾名思义就是暴露的意思,默认是开启的,关闭即可。

默认的情况,会在http协议的头部增加 X-Powered-By:PHP/x.x.x
php默认输出的版本号

php默认输出的版本号

php配置文件中,关于是否暴露版本号的描述。

; 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.
; http://php.net/expose-php
expose_php = On

翻译过来意思是说, 决定是否暴露你的服务器上是否安装了php, (例如会在web服务的头部增加一个签名),增加这个签名是没有任何安全问题的,同时可以告诉你,你的php是否正常运行。

修改的方法 修改php.ini 中的

;expose_php = On
expose_php = Off

隐藏php版本号的其他方法

在php中php-fpm的pool配置文件中设置

php_admin_flag[expose_php] = off

这种方法灵活性更强一些, 如果php同时有多pool 可以进行更细致的设置,就是部分poll设置,部分不设置。

回复

您的电子邮箱地址不会被公开。