tp5使用扩展类获取定位ip地址

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

控制器里:

<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\db\Query;
class Index extends Controller
{
    public function index()
    {
    	$ip = "114.118.99.174";
    	$Ip = new \IpLocation\IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件
    	$area = $Ip->getlocation($ip); // 获取某个IP地址所在的位置
    	print_r($area);die;
    }
}

踩过的一个小坑:

在类文件中没有定义命名空间,导致报xxxx方法不存在:

猜你喜欢

转载自blog.csdn.net/qq_42249896/article/details/85238541