Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php script to find web server name

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.


2 Answers

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

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).

like image 43
MAChitgarha Avatar answered Apr 01 '26 08:04

MAChitgarha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!