簡體   English   中英

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.90.207.67國家:巴西地區:城市:緯度:-23.5477經度:-46.6358

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

我從ISP的代碼中獲得的坐標,與GeoIPCity.dat不同,結果對於所有字段都是空的。

為什么網站和我的代碼的結果不同?

在線演示正在使用商業數據庫。 您的代碼正在查詢GeoLite數據庫。

您不應期望從兩個不同的數據庫獲得相同的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM