sablesoft/yii2-geoip

GeoIP component for yii2 application

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

v1.0.0 2020-07-06 14:29 UTC

This package is auto-updated.

Last update: 2024-05-06 23:32:59 UTC


README

Installation

The preferred way to install the geoip is through composer.

Either run

composer require sablesoft/yii2-geoip

or add

"sablesoft/yii2-geoip": "*",

to the require section of your composer.json.

Then add geoip in your app config:

    'components' => [
        'geoip'   => [
            'class'      => 'sablesoft\geoip\GeoIP',
            'dbPath'     => '/path/to/your/geoip/database'
        ]
    ]

How to Use

Use get method to get IP data:

$ip = "52.141.159.163";
/** @var \sablesoft\geoip\IpData $ipData */
$ipData = \Yii::$app->geoip->get($ip);
$country = $ipData->countryName;
$city   = $ipData->cityName;
$code = $ipData->countryCode;

$default = false;
$path = "some.path.in.ip.data.array";
$someData = $ipData->get($path, $default);