Manuel Pear

Net_GeoIP::lookupCountryName()

Net_GeoIP::lookupCountryName() --  returns full country name for specified IP address

Synopsis

  1. <?php
  2. require_once "Net/GeoIP.php
  3. ?> 

string lookupCountryName() (string $addr)

Description

This method returns the full country name for the given IP address. It works with both the free and the non-free databases.

Exemple 54-1. Looking up the country name

  1. <?php
  2. require_once "Net/GeoIP.php";  
  3.  
  4. $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat");  
  5.  
  6. try { 
  7.    echo $geoip->lookupCountryName($_SERVER['REMOTE_ADDR']);  
  8. } catch (Exception $e) { 
  9.    // Handle exception
  10. ?> 

Paramètres

  • 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:

    1. <?php
    2. $geoip->lookupCountryName(gethostbyname("example.com")  
    3. ?> 

    Or, if you don't know whether an address is a name or IP address, use application-level logic:

    1. <?php
    2. if (ip2long($ip_or_name) === false) { 
    3.    $ip = gethostbyname($ip_or_name);  
    4. } else { 
    5.    $ip = $ip_or_name;  
    6. }  
    7.  
    8. $country = $geoip->lookupCountryName($ip  
    9. ?> 

Valeurs renvoyées

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


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique