How to detect in PHP, if it is running on Apache, Nginx or some other webserver? [closed]

First I know this variable : _SERVER["SERVER_SOFTWARE"]

In one of my application, I want to check from PHP script which webserver it is running on. Basically it will be a wordpress plugin which will help Bloggers tweak some configure.

I have created separate process for Apache & Nginx and was also thinking about releasing code as 2 different wordpress plugins.

Then I just got curious to know if there is a FULLPROOF way in PHP to detect webservers flawlessly.

Please consider all cases :: Apache, Nginx, Apache + Nginx, PHP as Apache module, PHP using fastcgi, php-fpm, lighttpd, IIS, etc.

Also its critical for my application to detect combos and proxies presence.

Thanks,

-Rahul


Short answer is that its impossible to deterministically identify what webserver is in use. The closest you'll get is the value of $_SERVER["SERVER_SOFTWARE"].

It is possible to get a fairly good idea what software is running at a [particular URL by application fingerprinting but that's very very complicated - and it'll only tell you what's terminating the HTTP connection - it may be a proxy.

What you see in phpinfo() will not show the web server for [fast]cgi and it'll only show what the adminstrator chooses to make available on other systems.

Also its critical for my application to detect combos and proxies presence.

I have no idea what you mean by 'combos'. As for proxies....there is no way to tell that either.

Perhaps if you explained why you need this information and what value it has to you then we might be able to make a more informed guess as to an answer which might suit your needs.

C.