This method returns the full country name for the given IP address. It works with both the free and the non-free databases.
Example 48-1. Looking up the country name
|
string $addr - IP address
Lookups on Hostnames: Note that this PHP API does NOT support lookups on hostnames. This is so that the public API can be kept simple and so that the lookup functions don't need to try name lookups if IP lookup fails (which would be the only way to keep the API simple and support name-based lookups).
If you do not know the IP address, you can convert an name to IP very simply using PHP native functions or other libraries:
$geoip->lookupCountryName(gethostbyname("example.com"));Or, if you don't know whether an address is a name or IP address, use application-level logic:
if (ip2long($ip_or_name) === false) { $ip = gethostbyname($ip_or_name); } else { $ip = $ip_or_name; } $country = $geoip->lookupCountryName($ip);