ip归属地查询
创新互联主要从事成都做网站、网站设计、外贸营销网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务萨嘎,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
//查询ip归属地
function ipclient($ip){
$url = "http://api.k780.com:88/?app=ip.get&ip=$ip&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json";
$return = file_get_contents($url);
$arr = json_decode($return,true);
$arrs = explode(",",$arr['result']['area_style_areanm']);
return $arrs[1];
}
$array = array();
$iparray = array('1'=>'220.181.111.85', '2'=>'220.181.111.86', '3'=>'202.104.149.156', '4'=>'42.120.194.11', '5'=>'121.14.24.241');
//转变数组
foreach($iparray as $val){
$iparrs[] = array('address' => ipclient($val),'ip'=>$val);
}
$area = $re = $persons = array();
foreach ($iparrs as $key=>$val) {
$area[] = $val['address'];
}
$area = array_unique($area); //获取地区数组集合
foreach ($iparrs as $key=>$val) {
foreach ($area as $area_key=>$area_val) {
if ($val['address'] == $area_val) {
$persons[$area_key][] = $val['ip'];
$re[$area_key] = array(
'address' => $area_val,
'persons' => $persons[$area_key],
);
}
}
}
$re = array_values($re);
echo '
';print_r($re);
echo '
';?>
文章标题:ip归属地查询
文章源于:http://myzitong.com/article/ghgehp.html