DEV Community

IP Location API by ipwhois.io
IP Location API by ipwhois.io

Posted on

IP Geolocation & IP Location Lookup API

The service IP Geolocation is free for the test and small applications and sites.

Development
Due to powerful and optimized servers located on different continents and productive database, achieve a real response of up to 90 milliseconds in most parts of the world.

PHP Library
Go to Github Project

PHP Function

$ip = "CLIENT_IP_ADDRESS";
$location = get_ipwhois($ip);
$decodedLocation = json_decode($location, true);

echo "<pre>";
print_r($decodedLocation);
echo "</pre>";

function get_ipwhois($ip, $format = "json", $lang = "en") {
    $url = "http://free.ipwhois.io/".$format."/".$ip."?lang=".$lang;
    $cURL = curl_init();

    curl_setopt($cURL, CURLOPT_URL, $url);
    curl_setopt($cURL, CURLOPT_HTTPGET, true);
    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Accept: application/json'
    ));
    return curl_exec($cURL);
}
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
nag323 profile image
nag323

Great. Thanks for sharing.

geo.ipify.com also provides powerful IP Location Lookup API

Collapse
 
furqan_ashraf profile image
Furqan Ashraf

Nice writeup. For anyone comparing options, IPGeolocation.io is also worth a look if you need more than just location data. It returns timezone, currency, and ISP details in the same response, which saves a second API call if your app needs that info too. The free tier works fine for testing.