Home API How to do ip address lookup with php on ip-api.com

How to do ip address lookup with php on ip-api.com


ip-api.com is Free IP Geolocation API – lookup any IP address, this service uses the json api method where everyone can request api for free through their base api.

1. Create a function to call the visitor’s ip
function visitor_ip(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {

2. make API calls with curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://ip-api.com/json/".visitor_ip());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$result = curl_exec($ch2);
$data_ip = json_decode($result,true);

3. You can display data
$isp = $data_ip['isp'];
$country = $data_ip['country'];
$countryID = $data_ip['countryCode'];
$country = $data_ip['country'];
$region = $data_ip['region'];
$regionName = $data_ip['regionName'];
$city = $data_ip['city'];

For complete API documentation you can visit the official page https://ip-api.com/

Installer SSH & OpenVPN untuk VPS Debian 10 64 bit

Installing OpenVPN, OpenSSH, Dropbear, Squid SSH becomes easier and faster with the help of an installer script. You don't need Read more

Install Hostname SSL in DirectAdmin

DirectAdmin is a graphical web-based web hosting control panel that allows website administration via a web browser. The software can Read more

Previous articleInstalling ZCash mining on Ubuntu/Debian
Next articleLookup IP address with ipwhois.io in php


Please enter your comment!
Please enter your name here