PHP

Get IP And Location using PHP



Here is the PHP code snippet to display the ip address and geolocation based on the ip address to the visitors

 

Here is the code

<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo "<font face='Verdana' size='3'><b>IP Address= $ip</b>"; 
$url = "http://www.ipmango.com/api.php?ip=".$ip; $xml = simplexml_load_file($url);
echo "City : {$xml->city} <br />";
echo "Region : {$xml->region} <br />";
echo "Country Name : {$xml->countryname} <br />";
echo "Latitude : {$xml->latitude} <br />";
echo "Longitude : {$xml->longitude} <br />";
 ?>

Here is the demo

Thanks for reading my blog. If you like what I write, why not subscribe to my feed?

If you are busy, I can send the latest post to your email. Just subscribe to my email updates.

 

Enter your email address:

Delivered by FeedBurner

Discussion

No comments for “Get IP And Location using PHP”

Post a comment