【问题标题】:Reliable IP to Nation API [closed]可靠的 IP 到 Nation API [关闭]
【发布时间】:2023-03-09 06:36:01
【问题描述】:

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

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

【问题讨论】:

标签: api geolocation ip ip-geolocation


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2011-04-23
    相关资源
    最近更新 更多