Moodle  2.2.1
http://www.collinsharper.com
Net_GeoIP Class Reference

Public Member Functions

 __construct ($filename=null, $flags=null)
 open ($filename, $flags=null)
 close ()
 lookupCountryCode ($addr)
 lookupCountryName ($addr)
 lookupOrg ($addr)
 lookupRegion ($addr)
 lookupLocation ($addr)

Static Public Member Functions

static getInstance ($filename=null, $flags=null)

Data Fields

const ERR_INVALID_IP = 218624992
const ERR_DB_FORMAT = 866184008
const STANDARD = 0
const MEMORY_CACHE = 1
const SHARED_MEMORY = 2
const COUNTRY_BEGIN = 16776960
const STATE_BEGIN_REV0 = 16700000
const STATE_BEGIN_REV1 = 16000000
const STRUCTURE_INFO_MAX_SIZE = 20
const DATABASE_INFO_MAX_SIZE = 100
const COUNTRY_EDITION = 106
const REGION_EDITION_REV0 = 112
const REGION_EDITION_REV1 = 3
const CITY_EDITION_REV0 = 111
const CITY_EDITION_REV1 = 2
const ORG_EDITION = 110
const SEGMENT_RECORD_LENGTH = 3
const STANDARD_RECORD_LENGTH = 3
const ORG_RECORD_LENGTH = 4
const MAX_RECORD_LENGTH = 4
const MAX_ORG_RECORD_LENGTH = 300
const FULL_RECORD_LENGTH = 50
const US_OFFSET = 1
const CANADA_OFFSET = 677
const WORLD_OFFSET = 1353
const FIPS_RANGE = 360
const SHM_KEY = 0x4f415401

Static Public Attributes

static $COUNTRY_CODES
static $COUNTRY_CODES3
static $COUNTRY_NAMES

Protected Member Functions

 loadSharedMemory ($filename)
 setupSegments ()
 lookupCountryId ($addr)
 seekCountry ($ipnum)
 getOrg ($ipnum)
 getRegion ($ipnum)
 getRecord ($ipnum)

Detailed Description

Definition at line 136 of file GeoIP.php.


Constructor & Destructor Documentation

__construct ( filename = null,
flags = null 
)

Construct a Net_GeoIP instance. You should use the getInstance() method if you plan to use multiple databases or the same database from several different places in your script.

Parameters:
string$filenamePath to binary geoip database.
int$flagsFlags
See also:
getInstance()

Definition at line 333 of file GeoIP.php.

Here is the call graph for this function:


Member Function Documentation

close ( )

Closes the geoip database.

Returns:
int Status of close command.

Definition at line 561 of file GeoIP.php.

static getInstance ( filename = null,
flags = null 
) [static]

Calls the close() function to free any resources.

See also:
close()

COMMENTED OUT TO ADDRESS BUG IN PHP 5.0.4, 5.0.5dev. THIS RESOURCE SHOULD AUTOMATICALLY BE FREED AT SCRIPT CLOSE, SO A DESTRUCTOR IS A GOOD IDEA BUT NOT NECESSARILY A NECESSITY. public function __destruct() { $this->close(); } Singleton method, use this to get an instance and avoid re-parsing the db.

Unique instances are instantiated based on the filename of the db. The flags are ignored -- in that requests to for instance with same filename but different flags will return the already-instantiated instance. For example: // create new instance with memory_cache enabled $geoip = Net_GeoIP::getInstance('C:.dat', Net_GeoIP::MEMORY_CACHE); ....

// later in code, request instance with no flags specified. $geoip = Net_GeoIP::getInstance('C:.dat');

// Normally this means no MEMORY_CACHE but since an instance // with memory cache enabled has already been created for 'C:.dat', the // existing instance (with memory cache) will be returned.

NOTE: You can only use SHARED_MEMORY flag for one instance! Any subsquent instances that attempt to use the SHARED_MEMORY will use the *same* shared memory, which will break your script.

Parameters:
string$filenameFilename
int$flagsFlags that control class behavior. + Net_GeoIp::SHARED_MEMORY Use SHMOP to share a db among multiple PHP instances. NOTE: ONLY ONE GEOIP INSTANCE CAN USE SHARED MEMORY!!! + Net_GeoIp::MEMORY_CACHE Store the full contents of the database in memory for current script. This is useful if you access the database several times in a script. + Net_GeoIp::STANDARD [default] standard no-cache version.
Returns:
Net_GeoIP

Definition at line 392 of file GeoIP.php.

Here is the caller graph for this function:

getOrg ( ipnum) [protected]

Seek and return organization (or ISP) name for converted IP addr.

Parameters:
int$ipnumConverted IP address.
Returns:
string The organization

Definition at line 748 of file GeoIP.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getRecord ( ipnum) [protected]

Seek and populate Net_GeoIP_Location object for converted IP addr. Note: this

Parameters:
int$ipnumConverted IP address.
Returns:
Net_GeoIP_Location

Definition at line 812 of file GeoIP.php.

Here is the call graph for this function:

Here is the caller graph for this function:

getRegion ( ipnum) [protected]

Seek and return the region info (array containing country code and region name) for converted IP addr.

Parameters:
int$ipnumConverted IP address.
Returns:
array Array containing country code and region: array($country_code, $region)

Definition at line 772 of file GeoIP.php.

Here is the call graph for this function:

Here is the caller graph for this function:

loadSharedMemory ( filename) [protected]

Loads the database file into shared memory.

Parameters:
string$filenamePath to database file to read into shared memory.
Returns:
void
Exceptions:
PEAR_Exception- if unable to read the db file.

Definition at line 446 of file GeoIP.php.

Here is the caller graph for this function:

lookupCountryCode ( addr)

Returns 2-letter country code (e.g. 'CA') for specified IP address. Use this method if you have a Country database.

Parameters:
string$addrIP address (hostname not allowed).
Returns:
string 2-letter country code
Exceptions:
PEAR_Exception(see lookupCountryId())
See also:
lookupCountryId()

Definition at line 609 of file GeoIP.php.

Here is the call graph for this function:

lookupCountryId ( addr) [protected]

Get the country index.

This method is called by the lookupCountryCode() and lookupCountryName() methods. It lookups up the index ('id') for the country which is the key for the code and name.

Parameters:
string$addrIP address (hostname not allowed)
Exceptions:
PEAR_Exception- if IP address is invalid.
  • if database type is incorrect
Returns:
string ID for the country

Definition at line 586 of file GeoIP.php.

Here is the call graph for this function:

Here is the caller graph for this function:

lookupCountryName ( addr)

Returns full country name for specified IP address. Use this method if you have a Country database.

Parameters:
string$addrIP address (hostname not allowed).
Returns:
string Country name
Exceptions:
PEAR_Exception(see lookupCountryId())
See also:
lookupCountryId()

Definition at line 624 of file GeoIP.php.

Here is the call graph for this function:

lookupLocation ( addr)

Lookup the location record for given IP address. Use this method if you have a City database.

Parameters:
string$addrIP address (hostname not allowed).
Returns:
Net_GeoIP_Location The full location record.
Exceptions:
PEAR_Exception- if IP address is invalid.

Definition at line 728 of file GeoIP.php.

Here is the call graph for this function:

lookupOrg ( addr)

Lookup the organization (or ISP) for given IP address. Use this method if you have an Organization/ISP database.

Parameters:
string$addrIP address (hostname not allowed).
Exceptions:
PEAR_Exception- if IP address is invalid.
  • if database is of wrong type
Returns:
string The organization

Definition at line 684 of file GeoIP.php.

Here is the call graph for this function:

lookupRegion ( addr)

Lookup the region for given IP address. Use this method if you have a Region database.

Parameters:
string$addrIP address (hostname not allowed).
Returns:
array Array containing country code and region: array($country_code, $region)
Exceptions:
PEAR_Exception- if IP address is invalid.

Definition at line 706 of file GeoIP.php.

Here is the call graph for this function:

open ( filename,
flags = null 
)

Opens geoip database at filename and with specified flags.

Parameters:
string$filenameFile to open
int$flagsFlags
Returns:
void
Exceptions:
PEAR_Exceptionif unable to open specified file or shared memory.

Definition at line 410 of file GeoIP.php.

Here is the call graph for this function:

Here is the caller graph for this function:

seekCountry ( ipnum) [protected]

Using the record length and appropriate start points, seek to the country that corresponds to the converted IP address integer.

Parameters:
int$ipnumResult of ip2long() conversion.
Returns:
int Offset of start of record.
Exceptions:
PEAR_Exception- if fseek() fails on the file or no results after traversing the database (indicating corrupt db).

Definition at line 638 of file GeoIP.php.

Here is the caller graph for this function:

setupSegments ( ) [protected]

Parses the database file to determine what kind of database is being used and setup segment sizes and start points that will be used by the seek*() methods later.

Returns:
void

Definition at line 479 of file GeoIP.php.

Here is the caller graph for this function:


Field Documentation

$COUNTRY_CODES [static]
Initial value:
 array(
      "", "AP", "EU", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ",
      "AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH",
      "BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA",
      "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU",
      "CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG",
      "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", "GA", "GB",
      "GD", "GE", "GF", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT",
      "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN",
      "IO", "IQ", "IR", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
      "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS",
      "LT", "LU", "LV", "LY", "MA", "MC", "MD", "MG", "MH", "MK", "ML", "MM", "MN",
      "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA",
      "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA",
      "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY",
      "QA", "RE", "RO", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI",
      "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD",
      "TF", "TG", "TH", "TJ", "TK", "TM", "TN", "TO", "TL", "TR", "TT", "TV", "TW",
      "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN",
      "VU", "WF", "WS", "YE", "YT", "RS", "ZA", "ZM", "ME", "ZW", "A1", "A2", "O1",
      "AX", "GG", "IM", "JE", "BL", "MF"
        )

Definition at line 148 of file GeoIP.php.

$COUNTRY_CODES3 [static]
Initial value:
 array(
    "","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT","AGO","AQ","ARG",
    "ASM","AUT","AUS","ABW","AZE","BIH","BRB","BGD","BEL","BFA","BGR","BHR","BDI",
    "BEN","BMU","BRN","BOL","BRA","BHS","BTN","BV","BWA","BLR","BLZ","CAN","CC",
    "COD","CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI","CUB","CPV",
    "CX","CYP","CZE","DEU","DJI","DNK","DMA","DOM","DZA","ECU","EST","EGY","ESH",
    "ERI","ESP","ETH","FIN","FJI","FLK","FSM","FRO","FRA","FX","GAB","GBR","GRD",
    "GEO","GUF","GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","GS","GTM","GUM",
    "GNB","GUY","HKG","HM","HND","HRV","HTI","HUN","IDN","IRL","ISR","IND","IO",
    "IRQ","IRN","ISL","ITA","JAM","JOR","JPN","KEN","KGZ","KHM","KIR","COM","KNA",
    "PRK","KOR","KWT","CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU",
    "LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI","MMR","MNG","MAC",
    "MNP","MTQ","MRT","MSR","MLT","MUS","MDV","MWI","MEX","MYS","MOZ","NAM","NCL",
    "NER","NFK","NGA","NIC","NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER",
    "PYF","PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW","PRY","QAT",
    "REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN","SWE","SGP","SHN","SVN","SJM",
    "SVK","SLE","SMR","SEN","SOM","SUR","STP","SLV","SYR","SWZ","TCA","TCD","TF",
    "TGO","THA","TJK","TKL","TLS","TKM","TUN","TON","TUR","TTO","TUV","TWN","TZA",
    "UKR","UGA","UM","USA","URY","UZB","VAT","VCT","VEN","VGB","VIR","VNM","VUT",
    "WLF","WSM","YEM","YT","SRB","ZAF","ZMB","MNE","ZWE","A1","A2","O1",
    "ALA","GGY","IMN","JEY","BLM","MAF"
        )

Definition at line 171 of file GeoIP.php.

$COUNTRY_NAMES [static]

Definition at line 194 of file GeoIP.php.

const CANADA_OFFSET = 677

Definition at line 274 of file GeoIP.php.

const CITY_EDITION_REV0 = 111

Definition at line 263 of file GeoIP.php.

const CITY_EDITION_REV1 = 2

Definition at line 264 of file GeoIP.php.

const COUNTRY_BEGIN = 16776960

Definition at line 254 of file GeoIP.php.

const COUNTRY_EDITION = 106

Definition at line 260 of file GeoIP.php.

Definition at line 259 of file GeoIP.php.

const ERR_DB_FORMAT = 866184008

Exception error code when there is a DB-format-related error.

Definition at line 146 of file GeoIP.php.

const ERR_INVALID_IP = 218624992

Exception error code used for invalid IP address.

Definition at line 141 of file GeoIP.php.

const FIPS_RANGE = 360

Definition at line 276 of file GeoIP.php.

const FULL_RECORD_LENGTH = 50

Definition at line 271 of file GeoIP.php.

const MAX_ORG_RECORD_LENGTH = 300

Definition at line 270 of file GeoIP.php.

const MAX_RECORD_LENGTH = 4

Definition at line 269 of file GeoIP.php.

const MEMORY_CACHE = 1

Definition at line 250 of file GeoIP.php.

const ORG_EDITION = 110

Definition at line 265 of file GeoIP.php.

const ORG_RECORD_LENGTH = 4

Definition at line 268 of file GeoIP.php.

const REGION_EDITION_REV0 = 112

Definition at line 261 of file GeoIP.php.

Definition at line 262 of file GeoIP.php.

Definition at line 266 of file GeoIP.php.

const SHARED_MEMORY = 2

Definition at line 251 of file GeoIP.php.

const SHM_KEY = 0x4f415401

Definition at line 279 of file GeoIP.php.

const STANDARD = 0

Definition at line 249 of file GeoIP.php.

Definition at line 267 of file GeoIP.php.

const STATE_BEGIN_REV0 = 16700000

Definition at line 255 of file GeoIP.php.

const STATE_BEGIN_REV1 = 16000000

Definition at line 256 of file GeoIP.php.

Definition at line 258 of file GeoIP.php.

const US_OFFSET = 1

Definition at line 273 of file GeoIP.php.

const WORLD_OFFSET = 1353

Definition at line 275 of file GeoIP.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations