通过淘宝ip查询及remote_addr得到用户城市(脑残版)

来源:互联网 发布:运维常用linux命令 编辑:程序博客网 时间:2024/05/15 00:34
echo getCity("221.226.5.1");function getCity($ip){    //淘宝查询接口    $url = 'http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;    //用curl发送接收数据    $ch = curl_init($url);    curl_setopt($ch, CURLOPT_ENCODING, 'utf8');    curl_setopt($ch, CURLOPT_TIMEOUT, 10);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    $location = curl_exec($ch);    $location = json_decode($location);    curl_close($ch);    return($location->data->city);}//stdClass Object ( [code] => 0 [data] => stdClass Object ( [country] => 中国 [country_id] => CN [area] => 华东 [area_id] => 300000 [region] => 江苏省 [region_id] => 320000 [city] => 南京市 [city_id] => 320100 [county] => [county_id] => -1 [isp] => 电信 [isp_id] => 100017 [ip] => 221.226.5.1 ) ) 

0 0
原创粉丝点击