GeoIP2 PHP API v2.13.0

Reader
in package

Instances of this class provide a reader for the MaxMind DB format. IP addresses can be looked up using the get method.

Table of Contents

__construct()  : mixed
Constructs a Reader for the MaxMind DB format. The file passed to it must be a valid MaxMind DB file such as a GeoIp2 database file.
close()  : void
Closes the MaxMind DB and returns resources to the system.
get()  : mixed
Retrieves the record for the IP address.
getWithPrefixLen()  : array<string|int, mixed>
Retrieves the record for the IP address and its associated network prefix length.
metadata()  : Metadata

Methods

__construct()

Constructs a Reader for the MaxMind DB format. The file passed to it must be a valid MaxMind DB file such as a GeoIp2 database file.

public __construct(string $database) : mixed
Parameters
$database : string

the MaxMind DB file to use

Tags
throws
InvalidArgumentException

for invalid database path or unknown arguments

throws
InvalidDatabaseException

if the database is invalid or there is an error reading from it

Return values
mixed

close()

Closes the MaxMind DB and returns resources to the system.

public close() : void
Tags
throws
Exception

if an I/O error occurs

Return values
void

get()

Retrieves the record for the IP address.

public get(string $ipAddress) : mixed
Parameters
$ipAddress : string

the IP address to look up

Tags
throws
BadMethodCallException

if this method is called on a closed database

throws
InvalidArgumentException

if something other than a single IP address is passed to the method

throws
InvalidDatabaseException

if the database is invalid or there is an error reading from it

Return values
mixed

the record for the IP address

getWithPrefixLen()

Retrieves the record for the IP address and its associated network prefix length.

public getWithPrefixLen(string $ipAddress) : array<string|int, mixed>
Parameters
$ipAddress : string

the IP address to look up

Tags
throws
BadMethodCallException

if this method is called on a closed database

throws
InvalidArgumentException

if something other than a single IP address is passed to the method

throws
InvalidDatabaseException

if the database is invalid or there is an error reading from it

Return values
array<string|int, mixed>

an array where the first element is the record and the second the network prefix length for the record

metadata()

public metadata() : Metadata
Tags
throws
InvalidArgumentException

if arguments are passed to the method

throws
BadMethodCallException

if the database has been closed

Return values
Metadata

object for the database

Search results