zertex/yii2-zx-geoip-country

Yii 2 GeoIP extension. Returns country of current or specified IP (uses MaxMind's GeoIP2 databases)

1.0.2 2017-03-23 08:32 UTC

This package is not auto-updated.

Last update: 2024-04-13 17:46:41 UTC


README

Provides information about country of user by IP address.

Currently available:

  • Country
  • Country ISO Code

Install

Run

$ php composer.phar require zertex/yii2-zx-geoip-country "~1.0"

OR

add to your composer.json

{
    "require": {
        "zertex/yii2-zx-geoip-country": "~1.0"
    }
}

and run

$ php composer update

Usage

Like component

<?php

$config = [
    ...
    'components' => [
        'geoip' => ['class' => 'zertex\GeoIP\GeoIP'],
    ]
    ...
];

somewhere in code

$ip = Yii::$app->geoip->ip(); // current user ip

$ip = Yii::$app->geoip->ip("111.111.111.111");

$ip->country; // "United States"

Like object directly somewhere in your application

$geoip = new \zertex\GeoIP\GeoIP();
$ip = $geoip->ip("111.111.111.111");

$ip->country; // "United States"

This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com