可靠的IP到Nation API

时间:2010-12-24 01:56:10

标签: api geolocation ip ip-geolocation

我依靠YQL来进行一些IP到Nation的转换。那是个错误!

是否有任何可靠 IP到Nation API可通过REST或类似方式访问?

1 个答案:

答案 0 :(得分:2)

PHP函数......

function geoip($ip = "127.0.0.1"){

    if($ip == "127.0.0.1"){$ip = $_SERVER["REMOTE_ADDR"];}//if no IP specified use your own

    $ch = curl_init();//faster than file_get_contents()
    curl_setopt($ch, CURLOPT_URL,'http://www.geoplugin.net/php.gp?ip='.$ip);//fetch data from geoplugin.net
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $curl = curl_exec($ch);
    curl_close($ch);

    $geoip = unserialize($curl);
    return $geoip["geoplugin_countryName"]." ".$geoip["geoplugin_city"];//return country and city
}

有关服务的更多信息...... http://www.geoplugin.com/webservices/php