Get Apache Version and other installed software versions as associative array


/ Published in: PHP
Save to your folder(s)

this function return associative array from SERVER_SOFTWARE


Copy this code and paste it in your HTML
  1. function getServerSoftware($key = 'SERVER_SOFTWARE')
  2. {
  3. $regex = "/(?<software>\w+)\/(?<version>[0-9.a-z]*)/";
  4.  
  5. if(isset($_SERVER[$key]) && preg_match_all($regex, $_SERVER[$key], $arr))
  6. return array_combine($arr['software'], $arr['version']);
  7. else
  8. return array();
  9. }
  10.  
  11. //USAGE EXAMPLE
  12.  
  13. //get array
  14. $serverInfo = getServerInfo();
  15.  
  16. //print apache version
  17. echo $serverInfo['Apache'];
  18.  
  19. //print all information
  20. foreach($serverInfo as $software=>$version) echo "{$software}: {$version}<br>\n";

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.