Get City Country By IP Address in PHP

<?php /*Get user ip address*/
$ip_address=$_SERVER['REMOTE_ADDR'];
/*Get user ip address details with geoplugin.net*/
$geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address;
$addrDetailsArr = unserialize(file_get_contents($geopluginURL));
/*Get City name by return array*/
$city = $addrDetailsArr['geoplugin_city'];
/*Get Country name by return array*/
$country = $addrDetailsArr['geoplugin_countryName'];
/*Comment out these line to see all the posible details*/
/*echo '<pre>';
print_r($addrDetailsArr);
die();*/
if(!$city){
   $city='Not Define';
}if(!$country){
   $country='Not Define';
}
echo '<strong>IP Address</strong>:- '.$ip_address.'<br/>';
echo '<strong>City</strong>:- '.$city.'<br/>';
echo '<strong>Country</strong>:- '.$country.'<br/>';
?>

View Demo

Download Source Code(Get City Country By IP Address in PHP)
Size: 27 KB
Version: V 1
Leave A Reply

Your email address will not be published.

16 Comments
  1. krishna kant says

    code working fine but i want to state also..is this possible sir..

  2. Shamim Akhtar Sheikh says

    This code is not working .
    IP Address:- 1
    City:- Not Define
    Country:- Not Define

    1. Anuj Kumar says

      This will not work on localhost

  3. amarjit singh says

    its good it helps to maintain best sites

  4. princy says

    sir i want image processing project in php pls send me

    1. Anuj Kumar says

      Not available

  5. Dharmendra says

    Your Same Code Used in my Website but it give me this
    IP Address:- 103.216.215.125
    City:- Not Define
    Country:- Not Define

  6. pritty varghese says

    hii… its not working when I implement my code

    1. Anuj Kumar says

      while using this code you must connect with internet

      1. pritty varghese says

        put this code in live project.. But its not working

        1. Anuj Kumar says

          what error you are getting

  7. Dharmendra says

    Your Same Code Used in my Website but it give me this
    IP Address:- 103.216.215.125
    City:- Not Define
    Country:- Not Define

  8. pritty varghese says

    hii… its not working when I implement my code

    1. Anuj Kumar says

      while using this code you must connect with internet

      1. pritty varghese says

        put this code in live project.. But its not working

        1. Anuj Kumar says

          what error you are getting

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy