GeoIP已安装/加载,但未返回记录


GeoIP installed / loaded, but not returning records

尝试通过GeoIP模块/MaxMind数据库对国家和地区进行地理定位。

仔细检查它是通过phpinfo()加载的:

 geoip
 geoip support  enabled
 geoip extension version    1.0.8
 geoip library version  1004005

仔细检查DB:

    <?
    $db = geoip_database_info();
    print_r($db);
    ?>

退货:

GEO-106FREE 20090201 Build 1 Copyright (c) 2007 MaxMind LLC All Rights Reserved

但当我尝试这个:

<?
$record = geoip_record_by_name("76.109.14.196");
if ($record) {
   print_r($record);
}
?>

它变成一片空白。

我缺了一块吗?

数据库可能已过时。为什么不使用经过适当更新的远程解决方案,例如http://www.geoplugin.net/

的简单示例

$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=76.109.14.196");
echo $xml->geoplugin_countryName ;

输出

 United States

可能没有安装用于位置查找的特定数据库。尝试geoip_country_code_by_name,它应该可以工作。