PHP的ip地址获取类【Ip2Region】

Composer地址

composer require zoujingli/ip2region

使用方法

    // ip 定位
    public function getCity()
    {
        $ip = input('param.ip');

        $ip2region = new \Ip2Region();
        $info = $ip2region->btreeSearch($ip);

        $city = explode('|', $info['region']);

        if(0 != $info['city_id']){
            return json(['code' => 1, 'data' => $city['2'] . $city['3'] . $city['4'], 'msg' => 'ok']);
        }else{
            return json(['code' => 1, 'data' => $city['0'], 'msg' => 'ok']);
        }
    }

为您推荐

评论已关闭