php script to find web server name

2019-07-10 17:54发布

问题:

Is there any php script to find the name of the web server like apache, varnish, nginx, etc.

I know about netcraft and wappalyzer, but I want to have a script to run in my local machine

The main reason is, I have 4 servers in my local machine Apache2, nginx, Varnish and Lighty.

I have different ports for them like localhost:70 localhost:7070 etc. But all the servers root folder is /var/www/ and I have one index.php in /www which lists all the projects under /www folder.

I need some php script to echo the server name to insert in my index.php file, eg: if I use localhost:70 the script would detect its Apache and will display Apache, so on.

回答1:

You can get the server information using $_SERVER method in php.

$_SERVER['SERVER_SOFTWARE'] returns name like Apache/2.2.21 (Win32) PHP/5.3.10



回答2:

Use $_SERVER superglobal variable with the index of SERVER_SOFTWARE:

$serverSoftware = $_SERVER['SERVER_SOFTWARE'];

The above code gives you full name of server software. If you want to get just web server name, use this way:

$webServerName = explode('/', $serverSoftware)[0];

Note: The index of $_SERVER is case-sensitive. server_software doesn't work (as I tried before).



回答3:

Wappalyzer has a PHP port that you can run from the command line or a PHP script:

https://github.com/ElbertF/Wappalyzer#drivers
https://github.com/ElbertF/Wappalyzer/tree/master/drivers/php