查IP地址,淘宝的API

淘宝的API

// 淘宝归属地查询
function gettaobaoip($ip,$num = 1) {
    $ipapi = @file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip);
    $ipinfo = json_decode($ipapi, true);


    $country = $ipinfo['data']['country'];  //国家
    $country_id = $ipinfo['data']['country_id'];  //简称
    $area = $ipinfo['data']['area'];  //区域
    $region = $ipinfo['data']['region'];  //省份
    $city = $ipinfo['data']['city'];  //城市
    $isp = $ipinfo['data']['isp'];  //运营商
    $isp_id = $ipinfo['data']['isp_id'];  //运营商ID
    $ips = $ipinfo['data']['ip'];  //IP


    if ($region == $city) {
        $address = $region;
    } else {
        $address = $region . $city;
    }


    if ($num == '1') {
        $add = $country . ' ' . $address;
    } else {
        $add = $country . ' ' . $address . ' ' . $isp;
    }
    return $add;
}



调用


$iP = $_SERVER["REMOTE_ADDR"];
$location = getip($iP,0);
getip($iP,0) 这里getip(string,limit)

你可能感兴趣的:(查IP地址,淘宝的API)