Manuel Pear

Net_GeoIP::lookupLocation()

Net_GeoIP::lookupLocation() --  returns the location record for specified IP address

Synopsis

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

object lookupLocation() (string $addr)

Description

This method returns an instance of Net_GeoIP_Location for the specified IP address. It works only with a non-free City database.

Exemple 54-1. Looking up the location record

  1. <?php
  2. require_once "Net/GeoIP.php";  
  3.  
  4. $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat");  
  5.  
  6. try { 
  7.    $location = $geoip->lookupLocation($_SERVER['REMOTE_ADDR']); 
  8.  
  9.    var_dump($location); 
  10.  
  11.    printf("City: %s, %s\nLatitude: %s, Longitude: %s\n", 
  12.       $location->city, $location->region, 
  13.       $location->latitude, $location->longitude);  
  14.  
  15. } catch (Exception $e) { 
  16.    // Handle exception
  17. ?> 

Paramètres

  • string $addr - IP address

    Note : Hostnames are not supported. More information.

Valeurs renvoyées

This method throws an exception if the IP address is invalid.


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