Questioner
Questioner

Reputation: 7463

Can I check to see if an Apache module exists in PHP?

I run a number of sites across different servers. On some servers, the Apache server has the GeoIP module installed so that I can find out their location via their IP address. For example, to get their country name, I can do this:

$countryName = apache_note("GEOIP_COUNTRY_NAME");

However, on some servers that do not use the GeoIP module, this seems to cause troubles.

It seems that checking to see if $countryName comes back empty testing if apache_note("GEOIP_COUNTRY_NAME") exists with isset() is not good enough. I seem to just get HTML rendering failures without any error messages.

So, is there a way I can make an if statement in PHP to test to see if that GeoIP module exists in Apache?

(Note that on the servers where the GeoIP module is not installed I do not have access to the Apache settings, so installing the module is not an option.)

Upvotes: 3

Views: 2832

Answers (1)

Doon
Doon

Reputation: 20232

You should be able to use apache_get_modules http://php.net/manual/en/function.apache-get-modules.php to see if the module is loaded. Just check to see if the module is in the returned array. This apparently doesn't work if you are are calling PHP as a CGI though.

$mods = apache_get_modules();

if (array_search('mod_geoip',$mods)){
   print "GEO IP exist";
}else{
   print "GEO IP Doesn't Exist";
}

Upvotes: 4

Related Questions