简体   繁体   中英

PHP Getting the location from an IP address MaxMind GEOIP

I'm using PHP MaxMind GeoIP for getting the user's location. I did download both files to test: GeoLiteCity.dat and GeoIPCity.dat

Here is My php code:

$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);

Result:

Ip: 189.90.207.67 Country: Brazil Region: city: latitude: -23.5477 longitude: -46.6358

The returned coordinates are different from MaxMind: https://www.maxmind.com/en/geoip-demo ip: 189.90.207.67

The coordinates that I got in my code from my ISP, that different from GeoIPCity.dat which result was empty for all fields.

Why are the results of the site and of my code different?

The online demo is using the commercial database. Your codes are querying the GeoLite database.

You should not expect same results from two different databases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM