使用PHP根据IP地址定位用户所在的城市思路,调用淘宝提供的接口,根据IP地址定位!
function addressIP($clientIP) {
$getIP = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$clientIP;
$IPinfo = json_decode(file_get_contents($getIP));
$province = $IPinfo->data->region;
$city = $IPinfo->data->city;
$data = $province.$city;
return $data;
}
使用该函数时,传入IP地址,调用即可
$address = addressIP($clientIP);
echo $address;
![微笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
![微笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)