Question: I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it.

If anyone knows any better methods please share.

Thanks.

Answer: 
I use this:

```
  $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
  $ip = $_SESSION['ip'];
  $try1 = "http://ipinfodb.com/ip_query.php?ip=".$ip."&output=xml";
  $try2 = "http://backup.ipinfodb.com/ip_query.php?ip=".$ip."&output=xml";
  $XML = @simplexml_load_file($try1,NULL,TRUE);
  if(!$XML) { $XML = @simplexml_load_file($try2,NULL,TRUE); }
  if(!$XML) { return false; }

  //Retrieve location, set time
  if($XML->City=="") { $loc = "Localhost / Unknown"; }
  else { $loc = $XML->City.", ".$XML->RegionName.", ".$XML->CountryName; }
  $_SESSION['loc'] = $loc;

```
You can use Geolocation to get the Coordinates and then some Service to get the Country from that, but the geolocation API is browser based so you can only access it via JavaScript and then have to pass theese Informations to PHP somehow, i wrote something on the JS Part once:

<http://www.lautr.com/utilizing-html5-geolocation-api-and-yahoo-placefinder-example>

When it comes to getting the Location via the IP, there are a bazillion Services out there who offer databases for that, some free, some for charge, some with a lot of IP's stored and much data, some with less, for example the one you mentioned, works just fine:

<http://api.hostip.info/?ip=192.0.32.10>

So You can ether go with the Geolocation API which is pretty neat, but requires the users permission, works via JS and doesnt work in IE (so far) or have to look for a IPÜ Location Service that fits your needs :)