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: 
Try these:

<http://ip-to-country.webhosting.info/>

<http://www.ip2location.com/>

Both are IP address-to-country databases, which allow you to look up the country of origin of a given IP address.

However it's important to note that these databases are not 100% accurate. They're a good guide, but you will get false results for a variety of reasons.

* Many people use proxying to get around country-specific blocks and filters.
* Many IP ranges are assigned to companies with large geographic spread; you'll just get the country where they're based, not where the actual machine is (this always used to be a big problem for tracking AOL users, because they were all apparently living in Virginia)
* Control of IP ranges are sometimes transferred between countries, so you may get false results from that (especially for smaller/less well-connected countries)

Keeping your database up-to-date will mitigate some of these issues, but won't resolve them entirely (especially the proxying issue), so you should always allow for the fact that you will get false results.
**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 />";

```

}