Overview

Namespaces

  • GeoIp2
    • Database
    • Exception
    • Model
    • Record
    • WebService
  • PHP

Classes

  • Reader
  • Overview
  • Namespace
  • Class
  • Tree
  • Download

Class Reader

Instances of this class provide a reader for the GeoIP2 database format. IP addresses can be looked up using the country and city methods. We also provide cityIspOrg and omni methods to ease compatibility with the web service client, although we may offer the ability to specify additional databases to replicate these web services in the future (e.g., the ISP/Org database).

Usage

The basic API for this class is the same for every database. First, you create a reader object, specifying a file name. You then call the method corresponding to the specific database, passing it the IP address you want to look up.

If the request succeeds, the method call will return a model class for the method you called. This model in turn contains multiple record classes, each of which represents part of the data returned by the database. If the database does not contain the requested information, the attributes on the record class will have a null value.

If the address is not in the database, an GeoIp2\Exception\AddressNotFoundException exception will be thrown. If an invalid IP address is passed to one of the methods, a SPL InvalidArgumentException will be thrown. If the database is corrupt or invalid, a \MaxMind\Db\Reader\InvalidDatabaseException will be thrown.

GeoIp2\Database\Reader implements GeoIp2\ProviderInterface
Namespace: GeoIp2\Database
Located at GeoIp2/Database/Reader.php
Methods summary
public
# __construct( string $filename, array $locales = array('en') )

Constructor.

Constructor.

Parameters

$filename
The path to the GeoIP2 database file.
$locales
List of locale codes to use in name property from most preferred to least preferred.

Throws

MaxMind\Db\Reader\InvalidDatabaseException
if the database is corrupt or invalid
public GeoIp2\Model\City
# city( string $ipAddress )

This method returns a GeoIP2 City model.

This method returns a GeoIP2 City model.

Parameters

$ipAddress
IPv4 or IPv6 address as a string.

Returns

GeoIp2\Model\City
\GeoIp2\Model\City

Throws

GeoIp2\Exception\AddressNotFoundException
if the address is not in the database.
MaxMind\Db\Reader\InvalidDatabaseException
if the database is corrupt or invalid

Implementation of

GeoIp2\ProviderInterface::city()
public GeoIp2\Model\Country
# country( string $ipAddress )

This method returns a GeoIP2 Country model.

This method returns a GeoIP2 Country model.

Parameters

$ipAddress
IPv4 or IPv6 address as a string.

Returns

GeoIp2\Model\Country
\GeoIp2\Model\Country

Throws

GeoIp2\Exception\AddressNotFoundException
if the address is not in the database.
MaxMind\Db\Reader\InvalidDatabaseException
if the database is corrupt or invalid

Implementation of

GeoIp2\ProviderInterface::country()
public
# connectionType( mixed $ipAddress )
public
# domain( mixed $ipAddress )
public
# isp( mixed $ipAddress )
public MaxMind\Db\Reader\Metadata
# metadata( )

Returns

MaxMind\Db\Reader\Metadata
object for the database.

Throws

InvalidArgumentException
if arguments are passed to the method.
BadMethodCallException
if the database has been closed.
public
# close( )

Closes the GeoIP2 database and returns the resources to the system.

Closes the GeoIP2 database and returns the resources to the system.

GeoIP2 PHP API v0.9.0 API documentation generated by ApiGen 2.8.0