IP-Geolocation-API

IP Geolocation API - PHP SDK

Overview

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.

Quick Start Guide

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.

System Requirements

Internet connection is required to run this component.

Basic Usage

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:

Example

<?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);
    }
?>