tp5.1 根据IP地址获取用户所在省市(个人笔记)

class IPAddress extends Common
{
/**
* 根据ip地址,获取用户所在省市
*/
public function ipIndex()
{
$ip = "222.22.22.11";// 默认设置一个ip地址(可自行获取)
include "../vendor/topthink/Iplocation.php";//引入文件
$Ips =new \IpLocation\IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件
        $area = $Ips->getlocation($ip); // 获取某个IP地址所在的位置
print_r($area);die;
}

}


下载类文件:https://github.com/joytom/ipLocation

 

 

打印数据:

 
参考链接:https://blog.csdn.net/qq_42249896/article/details/85238541 

 

 

淘宝相关接口(浏览器访问):http://ip.taobao.com/service/getIpInfo.php?ip=222.22.22.11

 

 

 

 

 

posted @ 2019-11-06 11:21  小翼荨荨  阅读(1727)  评论(0编辑  收藏  举报