PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Networking » Net_Geo » Manual

Package for polling Netgeo service retrieving the geographical location of IPs or addresses.

Net_Geo - Example

Net_Geo - Example – tracking down the remote client IP

Example

<?php

require_once('Net/Geo.php');

// new Net_Geo object
$net_geo = new Net_Geo();

// fetch the client's IP
$ip = $_SERVER['REMOTE_ADDR'];

// fetch information array from net_geo
$results = $net_geo->getRecord($ip);

// output
echo "Single IP results:<br />";
echo "<pre>";
print_r($results);
echo "</pre>";

// example array of multiple IPs
$arr_ips = array
(
  gethostbyname("www.google.com"),
  gethostbyname("www.heise.de"),
  gethostbyname("www.college.ch")
);

// fetch information array from net_geo
$results = $net_geo->getRecord($arr_ips);

// output
echo "Multiple IP results:<br />";
echo "<pre>";
print_r($results);
echo "</pre>";

?>

Net_Geo::Net_Geo()

Net_Geo::Net_Geo() – constructor

Synopsis

require_once('Net/Geo.php');

bool Net_Geo() ( string $applicationName = '' , string $alternateServerUrl = '' )

Description

Create a new object for IP-based geographical information retrieval.

Parameter

Return value

boolean - Will always return true

Note

This function can not be called statically.

Net_Geo::getRecord()

Net_Geo::getRecord() – get geographical information about IP

Synopsis

require_once('Net/Geo.php');

array getRecord() ( mixed $target )

Description

Get geographical information about a list of targets or a single target. Error messages or "OK" are written to element STATUS of the returned array.

Parameter

Return value

array - Informative array about geographical location of target(s)

Throws

STATUS Error Codes
Error code Error message Reason Solution
string "OK" "No error occured." Target was resolved properly. NULL
const INPUT_ERROR "User input is unusable target" The target given cannot be used. Check target parameter: A string with a single domain or IP, or a one-dimensional array with domain or IP in every element
const NETGEO_HTTP_ERROR "Netgeo unreachable" A connection to the Netgeo service could not be established. Check http://netgeo.caida.org/perl/netgeo.cgi (the default server URL used). If the script moved, use the parameter $alternateServerUrl in Net_Geo().

Note

This function can not be called statically.