Dear Reader, In this Tutorial, let us we know that how we can get Country Details Like Country Name, Country Code, City, Region Code etc using IP Address, this is the simplest way, you just need to follow the following procedures and things will go on the fly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php $ip = '64.30.228.118'; $json_data = file_get_contents("http://apinotes.com/ipaddress/ip.php?ip=$ip"); //print_r($json_data); $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>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 } else { echo 'failed'; } ?> |
Output:-
1 |
{"status":"success","ip":"64.30.228.118","country_name":"United States","country_code":"US","country_code3":"USA","region_code":"FL","region_name":"Florida","city_name":"Fort Lauderdale","latitude":26.1882,"longitude":-80.1711} |
In the output, you can see “status” which is an important factor refers to as..
- If the “status=failed”, this means the IP Address is Invalid.
- If the “status=success”, then the Output will be displayed the IP Address details
Final Output:
Ip Address: 64.30.228.118
Country Name: United States
Country Code: US
Country Code(3 Digit): USA
Region Code: FL
City Name: Fort Lauderdale
Latitude: 26.1882
Longitude: -80.1711
2 Comments:
ltonIcext December 25, 2018
I am ltonser. I need help. What can i do it?
Webpreparations Team December 28, 2018
Which type of help you are asking from us Dear Itonser. Hope this article will help you http://www.webpreparations.com/display-country-state-city-using-google-api/