Get country by ip

Views: 1 Last modified: August 03rd, 2011 Comments: 0

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);
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {0+4} =  
    Anything to add ?

        You must be logged in to post a comment.