PHPackages                             mi-la01/kt\_maxmind\_geoip - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mi-la01/kt\_maxmind\_geoip

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mi-la01/kt\_maxmind\_geoip
==========================

MaxMind GeoIP2 PHP API

0.6.3(10y ago)08Apache-2.0PHPPHP &gt;=5.3.1

Since Jul 28Pushed 10y ago1 watchersCompare

[ Source](https://github.com/MI-LA01/kt_maxmind_geoip)[ Packagist](https://packagist.org/packages/mi-la01/kt_maxmind_geoip)[ Docs](https://github.com/maxmind/GeoIP2-php)[ RSS](/packages/mi-la01-kt-maxmind-geoip/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

GeoIP2 PHP API
==============

[](#geoip2-php-api)

Description
-----------

[](#description)

This package provides an API for the GeoIP2 \[web services\] () and \[databases\] (). The API also works with the free [GeoLite2 databases](http://dev.maxmind.com/geoip/geoip2/geolite2/).

Install via Composer
--------------------

[](#install-via-composer)

### Define Your Dependencies

[](#define-your-dependencies)

We recommend installing this package with [Composer](http://getcomposer.org/). To do this, add `geoip2/geoip2` to your `composer.json` file. If you don't have a `composer.json` file, create one in the root directory of your project.

```
{
    "require": {
        "geoip2/geoip2": "0.6.*"
    }
}
```

### Install Composer

[](#install-composer)

Run in your project root:

```
curl -s http://getcomposer.org/installer | php

```

### Install Dependencies

[](#install-dependencies)

Run in your project root:

```
php composer.phar install

```

### Require Autoloader

[](#require-autoloader)

You can autoload all dependencies by adding this to your code:

```
require 'vendor/autoload.php';

```

Installing via Phar
-------------------

[](#installing-via-phar)

Although we strongly recommend using Composer, we also provide a [phar archive](http://php.net/manual/en/book.phar.php) containing all of the dependencies for GeoIP2. Our latest phar archive is available on [our releases page](https://github.com/maxmind/GeoIP2-php/releases).

To use the archive, just require it from your script:

```
require 'geoip2.phar';
```

Optional C Extension
--------------------

[](#optional-c-extension)

The [MaxMind DB API](https://github.com/maxmind/MaxMind-DB-Reader-php)includes an optional C extension that you may install to dramatically increase the performance of lookups in GeoIP2 or GeoLite2 databases. To install, please follow the instructions included with that API.

The extension has no effect on web-service lookups.

Database Reader
---------------

[](#database-reader)

### Usage

[](#usage)

To use this API, you must create a new `\GeoIp2\Database\Reader` object with the path to the database file as the first argument to the constructor. You may then call the method corresponding to the database you are using.

If the lookup succeeds, the method call will return a model class for the record in the database. This model in turn contains multiple container classes for the different parts of the data such as the city in which the IP address is located.

If the record is not found, a `\GeoIp2\Exception\AddressNotFoundException`is thrown. If the database is invalid or corrupt, a `\MaxMind\Db\InvalidDatabaseException` will be thrown.

See the API documentation for more details.

### Example

[](#example)

```
