PHP从IP地址获取位置MaxMind GEOIP


PHP Getting the location from an IP address MaxMind GEOIP

我使用PHP MaxMind GeoIP来获取用户的位置。我确实下载了两个文件进行测试:GeoLiteCity.datGeoIPCity.dat

这是我的php代码:

$ip = "189.90.207.67";
$gi = geoip_open("data/GeoLiteCity.dat", GEOIP_STANDARD);
$record = geoip_record_by_addr($gi, $ip);
print "Ip: ".$ip."<br>";
print "Country: ".$record->country_name . "<br>";
print "Region: ".$record->region. "<br>";
print "city: ".$record->city . "<br>";
print "latitude: ".$record->latitude . "<br>";
print "longitude: ".$record->longitude . "<br>";
geoip_close($gi);

结果:

Ip:189.920.767国家:巴西地区:城市:纬度:-23.5477经度:-46.6358

返回的坐标与MaxMind不同:https://www.maxmind.com/en/geoip-demo ip: 189.90.207.67

我从ISP那里得到的代码中的坐标与GeoIPCity.dat,其结果对于所有字段都为空。

为什么网站和我的代码的结果不同?

在线演示使用商业数据库。您的代码正在查询GeoLite数据库。

您不应该期望来自两个不同数据库的结果相同。