GeoIP2 PHP API v2.4.4
  • Namespace
  • Class

Namespaces

  • GeoIp2
    • Database
    • Exception
    • Model
    • Record
    • WebService
  • MaxMind
    • Db
      • Reader
  • PHP

Classes

  • Reader

Class Reader

Instances of this class provide a reader for the GeoIP2 database format. IP addresses can be looked up using the database specific methods.

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

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

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 GeoIp2\Model\AnonymousIp
# anonymousIp( string $ipAddress )

This method returns a GeoIP2 Anonymous IP model.

This method returns a GeoIP2 Anonymous IP model.

Parameters

$ipAddress
IPv4 or IPv6 address as a string.

Returns

GeoIp2\Model\AnonymousIp

Throws

GeoIp2\Exception\AddressNotFoundException

if the address is not in the database.


MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

public GeoIp2\Model\ConnectionType
# connectionType( string $ipAddress )

This method returns a GeoIP2 Connection Type model.

This method returns a GeoIP2 Connection Type model.

Parameters

$ipAddress
IPv4 or IPv6 address as a string.

Returns

GeoIp2\Model\ConnectionType

Throws

GeoIp2\Exception\AddressNotFoundException

if the address is not in the database.


MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

public GeoIp2\Model\Domain
# domain( string $ipAddress )

This method returns a GeoIP2 Domain model.

This method returns a GeoIP2 Domain model.

Parameters

$ipAddress
IPv4 or IPv6 address as a string.

Returns

GeoIp2\Model\Domain

Throws

GeoIp2\Exception\AddressNotFoundException

if the address is not in the database.


MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

public GeoIp2\Model\Enterprise
# enterprise( string $ipAddress )

This method returns a GeoIP2 Enterprise model.

This method returns a GeoIP2 Enterprise model.

Parameters

$ipAddress
IPv4 or IPv6 address as a string.

Returns

GeoIp2\Model\Enterprise

Throws

GeoIp2\Exception\AddressNotFoundException

if the address is not in the database.


MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

public GeoIp2\Model\Isp
# isp( string $ipAddress )

This method returns a GeoIP2 ISP model.

This method returns a GeoIP2 ISP model.

Parameters

$ipAddress
IPv4 or IPv6 address as a string.

Returns

GeoIp2\Model\Isp

Throws

GeoIp2\Exception\AddressNotFoundException

if the address is not in the database.


MaxMind\Db\Reader\InvalidDatabaseException

if the database is corrupt or invalid

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 v2.4.4 API documentation generated by ApiGen