ip2region:PHP的ip地址获取类
PHP代码
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']);
}
}