geoip_record_by_addr实际上始终为null

时间:2014-03-19 10:59:34

标签: php null geoip maxmind

我在这个脚本中使用MaxMind GeoIP:

$gi = geoip_open(RESSOURCE_PATH.'/MaxMind/tests/data/GeoIPCity.dat', GEOIP_STANDARD);

// $rsGeoData = GeoIP_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
$rsGeoData = GeoIP_record_by_addr($gi, '91.213.180.118');

echo("<pre>");
print_r($rsGeoData);
echo("</pre>");

geoip_close($gi);

但$ rsGeoData始终为null(不是具有空值的数组,但实际上是&#34; null&#34;,即is_null($rsGeoData)===null)。 Null由geoipcity.inc文件的此函数返回:

function _get_record($gi, $ipnum)
{
    $seek_country = _geoip_seek_country($gi, $ipnum);
    if ($seek_country == $gi->databaseSegments) {
        return null;
    }
    return _common_get_record($gi, $seek_country);
}

我真的无法理解为什么......你能帮助我吗?

1 个答案:

答案 0 :(得分:1)

从您的文件路径,我猜测您正在使用为单元测试而不是完整数据库创建的数据库。我建议从MaxMind下载GeoLite database