Home API Lookup IP address with ipwhois.io in php

Lookup IP address with ipwhois.io in php

195
0

ipwhois.io servers are distributed worldwide for speed, reliability and security. This service is paid but this time I will share how to use this service for free.

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

2. make API calls with curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://ipwhois.app/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['country_code'];
$country = $data_ip['country'];
$region = $data_ip['region'];
$city = $data_ip['city'];

Here is a sample JSON Output from the server
{"ip":"8.8.8.8","success":true,"type":"IPv4","continent":"North America","continent_code":"NA","country":"United States","country_code":"US","country_flag":"https:\/\/cdn.ipwhois.io\/flags\/us.svg","country_capital":"Washington","country_phone":"+1","country_neighbours":"CA,MX,CU","region":"California","city":"Mountain View","latitude":37.3860517,"longitude":-122.0838511,"asn":"AS15169","org":"Google LLC","isp":"Google LLC","timezone":"America\/Los_Angeles","timezone_name":"Pacific Standard Time","timezone_dstOffset":0,"timezone_gmtOffset":-28800,"timezone_gmt":"GMT -8:00","currency":"US Dollar","currency_code":"USD","currency_symbol":"$","currency_rates":1,"currency_plural":"US dollars","completed_requests":7}

Now you have successfully created a fire lookup for free

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 articleHow to do ip address lookup with php on ip-api.com
Next articleHow to do an ip address lookup via extreme-ip-lookup.com in php

LEAVE A REPLY

Please enter your comment!
Please enter your name here