14

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

rahul286
  • 1,647
  • 5
  • 20
  • 25

2 Answers2

10

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.

symcbean
  • 21,009
  • 1
  • 31
  • 52
  • By cambo I simply mean - some users choose Nginx as front-end web server and then use Apache to run PHP. One case is that they want to run cpanel and nginx together. Now in my application, in one section, I want to guide users for some complex rewrite rule based on webserver. In above apache+nginx case, which web-server my PHP script will detect? I – rahul286 Jul 28 '10 at 15:15
0

Someone on the PHP Manual site posted a way to get phpinfo() variables into an array, there's lots of information there but also the System where php is running, maybe you can use that. Look at the comments.

Also, detecting proxies is not that easy, you can use http headers (like Via) but there're a lot of ways that it can go wrong.

coredump
  • 12,713
  • 2
  • 36
  • 56
  • thanks for your answer and help. I know via headers cannot be trusted and that is the reason I am seeking some help. – rahul286 Jul 28 '10 at 15:16