This IP Geolocation API service is designed for quick and easy visitors IP geolocation integration into your script or website. Get rid of setting up local GeoIP libraries and forget about regular updates. Our neural network analyzes dozens of sources and almost real-time updates the database.
You can call the API by sending HTTP GET requests to http://ipwho.is/{IP}
{IP}
can be an IPv4 or IPv6 address, or none to use the current IP address.
Note: Complete documentation to use this API is also available at IP Geolocation API Documentation.
Internet connection is required to run this component.
Call method get_ipwhois($ip, $format, $lang, $apiKey)
passing IP address as parameters (rest of the parameters are optional) and it will return the Geolocation for the passed IP address. To customize the geolocation response, you can pass the other parameters to get_ipwhois()
method as described below:
$format
Based on your choice, the ipwhois API can deliver results in:$lang
Pass the language parameter to get the geolocation information in a language other than English. By default, it is set to English language.<?php
$ip = "8.8.4.4"; // CLIENT IPADDRESS
$apiKey = ""; // Leave blank for free endpoint
$location = get_ipwhois($ip,'json','en',$apiKey);
echo "<pre>";
print_r($location);
echo "</pre>";
function get_ipwhois($ip, $format = "json", $lang = "en", $apiKey = "") {
$url = "http://".($apiKey != '' ? 'ipwhois.pro' : 'ipwho.is')."/".$ip."?lang=".$lang.($apiKey != '' ? '&key='.$apiKey : '')."&output=".$format;
$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 json_decode(curl_exec($cURL),true);
}
?>