Get the Apache and PHP Version Info

by jeremyjones on March 9, 2011

  • Share
  • CevherShare
  • Share

If you are developing PHP code for a website you might sometimes want to check which version of Apache or PHP will be running the website. This is particularly true if you use some functionality that was included at a particular revision of the software or if you want to avoid security holes that were present in an older version. There are two simple ways to get this information using phpinfo() or the SERVER_SIGNATURE:

<?php phpinfo(); ?>

Or

$_SERVER[“SERVER_SIGNATURE”]

Both of these will return a lot of extra information to just the Apache and PHP versions. One way to reduce the amount of information is to split the array returned by $_SERVER and only keep the parts you are interested in. This approach is shown in the following example:

// Splits the output into an array
$ar = split("[/ ]",$_SERVER['SERVER_SOFTWARE']);
// Loops through the array
>for ($i=0;$i<(count($ar));$i++)
{

switch(strtoupper($ar[$i]))
{
// Gets the Apache Version
>case 'APACHE':
$i++;
$Apache_Ver = $ar[$i];

break;
// Gets the PHP Version
>case 'PHP':
$i++;
$PHP_Ver = $ar[$i];

break;
}

As well as the Apache and PHP information obtained in the example, this approach can be used to obtain information about the software running on the server.

Leave a Comment

Previous post:

Next post: