doudao9915 2015-11-05 16:52
浏览 45

PHP从IP地址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?

  • 写回答

1条回答 默认 最新

  • douqie1884 2015-11-06 07:40
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题