Can I check if the Apache module exists in PHP?

I run several sites on different servers. GeoIP is installed on some servers on the Apache server, so I can find out their location by their IP address. For example, to get the name of my country, I can do this:

$countryName = apache_note("GEOIP_COUNTRY_NAME");

However, on some servers that do not use the GeoIP module, this appears to be causing problems.

It seems that checking that $countryName comesreturns empty testing if apache_note("GEOIP_COUNTRY_NAME")exists with isset()is not enough. It seems like I'm just getting HTML rendering errors without error messages.

So, is there a way to make an expression ifin PHP to check if this GeoIP module exists in Apache?

(Note that on 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.)

+3
source share
1 answer

You can use apache_get_modules http://php.net/manual/en/function.apache-get-modules.php to find out if the module is loaded. Just check if the module is in the returned array. This does not seem to work if you call PHP as CGI.

$mods = apache_get_modules();

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

All Articles