Net_GeoIP::lookupCountryCode()

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

Synopsis

require_once "Net/GeoIP.php";

string lookupCountryCode() ( string $addr )

Description

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

<?php
require_once "Net/GeoIP.php";

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

try {
    echo 
$geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']);
} catch (
Exception $e) {
    
// Handle exception
}
?>

Parameter

  • string $addr - IP address

    Note: Hostnames are not supported. More information.

Throws

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

Net_GeoIP::lookupCountryName() (Previous) Net_GeoIP::lookupRegion() (Next)
Last updated: Tue, 02 Jun 2009 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.