$ip = '';
$url = "http://www.ipmango.com/api.php?ip=".$ip;
$xml = simplexml_load_file($url);
echo "IP address : {$xml->ipaddress} <br />";
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 />";

Edited by pritaeas: Added markdown.

9 Years
Discussion Span
Last Post by Pramod_7

Hi theausum,

Two things:

Firstly, please use code tags when posting code. It really does make it a lot easier to read.
Secondly, did you have a question?


Sorry for not using the code tags.
I did not have any question.
I have just provided the php code to find visitor's location.


if you want accurate geo location with low latency and the ability for the api to handle your websites traffic, the best solution out there is http://geolify.com .Geolify can also be used as a website personalization tool where you can deliver geo targeted content, images and url redirects with only a single line of javascript making it easy for website owners to geo target their website. If you just need location, you can use their geo javascript to determine country, state, city and coordinates very easily.


not this code is not working .....having error to open http stream

Warning: simplexml_load_file(htt/./ww.w.p:ipmango.com/api.php?ip= failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in C:\xampp\htdocs\demo\demo2.php on line 4


Edited by Pramod_7


i had tried this code but not working .....for accessing the information we have Geo
Api plugin ...ip address works perfect and country name also but another variable like city region not provide any appropriate value

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.