user1376704
user1376704

Reputation:

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.

Upvotes: 3

Views: 7642

Answers (3)

MAChitgarha
MAChitgarha

Reputation: 4288

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

Upvotes: 1

user1432124
user1432124

Reputation:

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

Upvotes: 4

Elbert Alias
Elbert Alias

Reputation: 1790

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

Upvotes: 0

Related Questions