Rants of a madman » 2008 » May

Archive for May, 2008

May
23

Problem:PHP displays its version along with the normal webserver response headers. Apparently the only way to change this, is recompiling PHP. Which i find annoying to do after every PHP update.. So i decided to make a one-liner to patch the binary PHP module.

Solution:

This has been tested only on PHP4 and PHP5 on Debian, but i see no reason why it shouldnt work on other distro’s.

Locate your libphp4.so, libphp5.so or the likes. Mine is in /usr/lib/apache/1.3/libphp4.so (on Debian). And make a backup of it just in case ;)
Run the following command:

perl -pi -e "s/(X-Powered-By: PHP).([^\x00]+)/$1\x00$2/" /usr/lib/apache/1.3/libphp4.so

(replace /usr/lib/apache/1.3/libphp4.so with YOUR path)

Restart apache. Now headers only reveal “X-Powered-By: PHP"



  - Dan