views:

311

answers:

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?

+6  A: 

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.

Pekka
+3  A: 

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
Gumbo
That isn't working on my production server. It's working on my local machine though. Any ideas as to why this is happening?
Castor
@Castor What server versions are you using locally and on the production machine? Any differences in the PHP setup?
Pekka
PHP Version on production: PHP/5.2.13PHP Version on local: PHP/5.2.11Apache version on production: Apache/2.2.15 (Unix)Apache version on local: Apache 2.0.63 (using MAMP on Mac)
Castor
@Castor: Is mod_headers available on both servers? And are you allowed to override *FileInfo* (see http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride)?
Gumbo
@Gumbo Yes, mod_headers is available on both the servers. And yes, I am allowed to override FileInfo.
Castor
@Castor: Hm, then I don’t see any reason why this wouldn’t work.
Gumbo
A: 

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

MainMa
Well, I got this working from the php code. header("X-Powered-By: "); Setting the X-Powered-By header to nothing removed it.Thanks all for your time and suggestions.
Castor