Getting visitors country from their IP,get ip address country php,Get Country of IP Address with PHP,geolocation ,Get Country By IP Address in PHP

IP Address details for the country name, country code, region name, region code, city name, latitude and longitude. json, php, dot net, asp.net, website, javascript, jquery. Getting visitors country from their IP, get ip address country php, Get Country of IP Address with PHP, geo Location, Get Country By IP Address in PHP


How to Get Country Details from IP Address in PHP


How to Get Country Details from IP Address in PHP

To get the IP Address details for the country name, country code, region name, region code, city name, latitude and longitude of IP address is by following procedures have to be done.

First of all let’s try using apinotes.com api,

http://apinotes.com/ipaddress/ip.php?ip=27.62.184.235

 

http://apinotes.com/ipaddress/ip.php?ip=27.62.184.235

  • URL:  http://apinotes.com/ipaddress/ip.php
  • Parameter Name: ip
  • Value:  27.62.184.23 (ipv4 address)

Output:-

Here we display the IP address details in Json query format.

{ 
   "status":"success",
   "ip":"27.62.184.23",
   "country_name":"India",
   "country_code":"IN",
   "country_code3":"IND",
   "region_code":"16",
   "region_name":"Maharashtra",
   "city_name":"Mumbai",
   "latitude":18.975,
   "longitude":72.8258
}

 

In the output the “status” which as an important factor refers to as shown below,

  • If the “status=failed”, then it means the IP Address is invalid.
  • In case, if the “status= success”, then the output will display the IP address details.

Note: - Here using GET method and where you can pass the IP Address value and retrieve IP address information’s.

Example For Get Country Details By Ip Address In Php

<?php
$ip = '27.62.184.235';
$json_data = file_get_contents("http://apinotes.com/ipaddress/ip.php?ip=$ip");
$ip_data = json_decode($json_data, TRUE);
if ($ip_data['status'] == 'success') {
    ?>
    <p>Ip Address: <?php echo $ip_data['ip'] ?></p>
    <p>Country Name: <?php echo $ip_data['country_name'] ?></p>
    <p>Country Code: <?php echo $ip_data['country_code'] ?></p>
    <p>Country Code (3 digit): <?php echo $ip_data['country_code3'] ?></p>
    <p>Region Code: <?php echo $ip_data['region_code'] ?></p>
    <p>Region Name: <?php echo $ip_data['region_name'] ?></p>
    <p>City Name: <?php echo $ip_data['city_name'] ?></p>
    <p>Latitude: <?php echo $ip_data['latitude'] ?></p>
    <p>Longitude: <?php echo $ip_data['longitude'] ?></p>
<?php }
?>

 

OUTPUT:-

Ip Address: 27.62.184.235

Country Name: India

Country Code: IN

Country Code(3 digit): IND

Region Code: 28

Region Name: West Bengal

City Name: Kolkata

Latitude: 22.5697

Longitude: 88.3697

About Author


API Notes

We are a professional tutorial site on the programming languages like C, C++, Java, .Net, Php and the web development languages like Html, Css, and JavaScript. We train people on the database programming like MySQL, SQL, and Oracle.

Leave a comment


Leave A Reply