WhatsApp us

How to get Country State City by IP Address in PHP

  • Tech Area
  • Last updated on: January 8, 2026


I am working on a project where I need to show country, state and city of the user by taking his IP address. How do I get in PHP.

Solution

<?php 
$ip_address = $_SERVER['REMOTE_ADDR'];

$ipAPI='http://ip-api.com/php/'.$ip_address;
$resArr = unserialize(file_get_contents($ipAPI));

if($resArr)
{
     echo 'Your Country is ' . $resArr['country'];
     echo '<br />';
     echo 'Your State is ' . $resArr['region'];
     echo '<br />';
     echo 'Your City is ' . $resArr['city'];
}
?>


Subscribe us via Email

Join 20,000+ subscriber

Subscribe on YouTube

PHP Projects
Matrimonial Portal Project in PHP & MySQL Last Updated: December 22, 2025
Event Management System Project in PHP & MySQL Last Updated: December 6, 2025
Online Shopping System Project in PHP MySQL Last Updated: November 26, 2025
Hostel management system project in PHP and MySQL Last Updated: February 14, 2024
Online Pizza Delivery project in PHP Last Updated: February 4, 2024
Parking Management System project in PHP Last Updated: November 5, 2023
Visitors Management System project in PHP Last Updated: August 28, 2023
SNIPE – IT Asset management system v6.1.0 Last Updated: April 21, 2023
Employee Management System project in PHP Last Updated: January 21, 2023