Net_GeoIP::lookupCountryCode() – returns 2-letter country code (e.g. "CA") for specified IP address


require_once "Net/GeoIP.php";

string lookupCountryCode() ( string $addr )


This method returns the 2-letter country code for the given IP address. It works with both the free and the non-free databases.

Looking up the country code

require_once "Net/GeoIP.php";

$geoip Net_GeoIP::getInstance("/path/to/geoipdb.dat");

try {
} catch (
Exception $e) {
// Handle exception



This method throws an exception if the IP address is invalid or if the database type is incorrect.

returns full country name for specified IP address (Previous) returns the region for given IP address. (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.