This function will return a array -> Index 0: Country, Index 1: IP. Just feed it with the IP and the function will do the rest.
function CountryByIp($ip)
{
// Get XML
$XmlContent = file_get_contents('http://api.hostip.info/?ip='.$ip);
// Get the country
preg_match('#<countryName>(.*?)</countryName>#', $XmlContent, $result);
// Return the country
return $result[1];
}
echo CountryByIp($ip);
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)

» Latest comments