您的位置:首页 > 编程语言 > PHP开发

原生态php在线获取IP定位

2017-02-21 16:51 274 查看

原生态php在线获取IP定位

<?php
/**
* 获取 IP  地理位置
* 在线获取地理位置
* 淘宝IP接口
* @Return: array
*/
function getCity($ip = '')
{
if($ip == ''){
$url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json";
$ip=json_decode(file_get_contents($url),true);
$data = $ip;
}else{
$url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
$ip=json_decode(file_get_contents($url));
if((string)$ip->code=='1'){
return false;
}
$data = (array)$ip->data;
}
return $data;
}

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php