1

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

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

4

1 回答 1

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

于 2010-12-24T02:03:45.570 回答