GeoIP PHP API v3.5.0

Reader
in package
implements ProviderInterface

Instances of this class provide a reader for the GeoIP 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 exception will be thrown. If an invalid IP address is passed to one of the methods, a SPL will be thrown. If the database is corrupt or invalid, a will be thrown.

Table of Contents

Interfaces

ProviderInterface

Properties

$locales  : array<string|int, string>

Methods

__construct()  : mixed
Constructor.
anonymousIp()  : AnonymousIp
This method returns a GeoIP Anonymous IP model.
anonymousPlus()  : AnonymousPlus
This method returns a GeoIP Anonymous Plus model.
asn()  : Asn
This method returns a GeoLite ASN model.
city()  : City
This method returns a GeoIP City model.
close()  : void
Closes the GeoIP database and returns the resources to the system.
connectionType()  : ConnectionType
This method returns a GeoIP Connection Type model.
country()  : Country
This method returns a GeoIP Country model.
domain()  : Domain
This method returns a GeoIP Domain model.
enterprise()  : Enterprise
This method returns a GeoIP Enterprise model.
isp()  : Isp
This method returns a GeoIP ISP model.
metadata()  : Metadata

Properties

$locales read-only

public array<string|int, string> $locales = ['en']

Methods

__construct()

Constructor.

public __construct(string $filename[, array<string|int, string> $locales = ['en'] ]) : mixed

The declared exceptions come from the pure-PHP reader. The C extension may differ.

Parameters
$filename : string

the path to the GeoIP database file

$locales : array<string|int, string> = ['en']

list of locale codes to use in name property from most preferred to least preferred

Tags
throws
InvalidDatabaseException

if the database is corrupt or invalid

InvalidArgumentException

if the database file does not exist or is not readable

RuntimeException

with the pure PHP reader, if metadata decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

UnexpectedValueException

if the size of the database file cannot be determined

anonymousIp()

This method returns a GeoIP Anonymous IP model.

public anonymousIp(string $ipAddress) : AnonymousIp
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
AnonymousIp

anonymousPlus()

This method returns a GeoIP Anonymous Plus model.

public anonymousPlus(string $ipAddress) : AnonymousPlus
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
AnonymousPlus

asn()

This method returns a GeoLite ASN model.

public asn(string $ipAddress) : Asn
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
Asn

city()

This method returns a GeoIP City model.

public city(string $ipAddress) : City
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
City —

a City model for the requested IP address

close()

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

public close() : void
Tags
throws
BadMethodCallException

if the database has already been closed

connectionType()

This method returns a GeoIP Connection Type model.

public connectionType(string $ipAddress) : ConnectionType
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
ConnectionType

country()

This method returns a GeoIP Country model.

public country(string $ipAddress) : Country
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
Country —

a Country model for the requested IP address

domain()

This method returns a GeoIP Domain model.

public domain(string $ipAddress) : Domain
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
Domain

enterprise()

This method returns a GeoIP Enterprise model.

public enterprise(string $ipAddress) : Enterprise
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
Enterprise

isp()

This method returns a GeoIP ISP model.

public isp(string $ipAddress) : Isp
Parameters
$ipAddress : string

an IPv4 or IPv6 address as a string

Tags
throws
AddressNotFoundException

if the address is not in the database

InvalidDatabaseException

if the database is corrupt or invalid

BadMethodCallException

if the database type does not support this method, the reader is closed, or a lookup is in progress (pure PHP reader 1.14.0 and later)

InvalidArgumentException

if the IP address is not valid, or if it is an IPv6 address and the database is IPv4-only

RuntimeException

with the pure PHP reader, if decoding needs gmp or bcmath and neither is installed, or a data offset exceeds the platform limit

Return values
Isp

metadata()

public metadata() : Metadata
Tags
throws
BadMethodCallException

if the database has been closed

InvalidDatabaseException

with the C extension, if the metadata cannot be decoded

Return values
Metadata —

object for the database

On this page

Search results