开发者

Good php API for extracting country code from IP? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting 开发者_如何学编程answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 6 years ago.

Improve this question

I'm wondering has anyone had any experience in doing a whois on an IP and extracting the country code from that IP? Wondering what api would be the cleanest way of doing this with php.


Have a look at the MaxMind GeoIP database. They have a PHP API.


You can use my service, the http://ipinfo.io API for this:

Assuming you want all of the details, you can use PHP's json_decode to parse the response:

function ip_details($ip) {
    $json = file_get_contents("http://ipinfo.io/{$ip}");
    $details = json_decode($json);
    return $details;
}

$details = ip_details("8.8.8.8");

echo $details->city;     // => Mountain View
echo $details->country;  // => US
echo $details->org;      // => AS15169 Google Inc.
echo $details->hostname; // => google-public-dns-a.google.com

JSONP is also supported, so you can call the API from javascript:

$.get("http://ipinfo.io", function(response) {
    console.log(response.city);
}, "jsonp");

More details are available at http://ipinfo.io/developers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜