【问题标题】:How to check GEOIP module in installed in my server如何检查安装在我的服务器中的 GEOIP 模块
【发布时间】:2013-11-23 07:48:24
【问题描述】:
我正在使用一个使用 GEOIP 模块的插件。我不确定这个模块是否安装在我的服务器中,因为这是一个共享服务器。
我需要一些 php 脚本来检查是否安装了这个模块。
我找到了这个脚本:
$mods = apache_get_modules();
if (array_search('mod_geoip',$mods)){
print "GEO IP exist";
}else{
print "GEO IP Doesn't Exist";
}
但最终出现此错误:
致命错误:调用未定义的函数 apache_get_modules()
第 2 行的 testmodule.php
【问题讨论】:
标签:
php
geolocation
geoip
【解决方案1】:
我有同样的问题要确定 geoip 是否安装为 apache 模块。
但是geoip(作为apache-mod)提供了一些功能来查找例如国家代码。
这就是重点,您必须使用 php functions_exists() 检查是否存在某些 geoip 功能。
我自己测试了这个解决方案。
我使用该功能的原因是将我的工具移动到具有不同 apache-mods(如“geoip”等)的许多服务器上。希望这个解决方案有用!?
if ( function_exists("geoip_country_code_by_name") ){
$geoip = geoip_country_code_by_name($_SERVER["REMOTE_ADDR"]);
} else {
include($_SERVER['DOCUMENT_ROOT'] . "/geoip/geoip.inc");
include($_SERVER['DOCUMENT_ROOT'] . "/geoip/geoipregionvars.php");
$gi = geoip_open($_SERVER['DOCUMENT_ROOT'] . "/geoip/data/GeoIP.dat",GEOIP_STANDARD);
$geoip = geoip_country_code_by_addr($gi,$_SERVER['REMOTE_ADDR']);
geoip_close($geoip);
}