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;

```
**Try these:**

$key="9dcde915a1a065fbaf14165f00fcc0461b8d0a6b43889614e8acdb8343e2cf15";
$ip= "198.168.1230.122";

$url = "<http://api.ipinfodb.com/v3/ip-city/?key=>$key&ip=$ip&format=xml";

// load xml file

$xml = simplexml\_load\_file($url);
// print the name of the first element

echo $xml->getName() . "  
";
// create a loop to print the element name and data for each node

foreach($xml->children() as $child)

{

```
echo $child->getName() . ": " . $child . "<br />";

```

}