Yii2 Component to allow for easy usage of the MaxMind Free dbs
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
db
.gitignore Add db and update gitignore Jun 12, 2018
LICENSE Initial commit Jun 12, 2018
README.md
composer.json

README.md

Yii2 GeoIP - City DB version

Yii2 Component to allow for easy usage of the MaxMind Free dbs.

Based on package phiphi1992/Yii2-GeoIP by Phi Hoang Xuan.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require dpodium/yii2-geoip-city-db "~0.2"

or add

"dpodium/yii2-geoip-city-db "~0.2"

to the require section of your composer.json file.

Component Setup

Once the extension is installed, simply modify your application configuration as follows:

return [
    'components' => [
    ...
        'geoip' => [
                   'class' => 'dpodium\yii2\geoip\components\CGeoIP',
               ],
        ...
    ],
    ...
];

If querying only partial Country data is required, yii2-geoip can be used instead and is lighter in terms of repo size, see dpodium/yii2-geoip.

For more information on the data availability, see below.

Usage

All methods accept an IP address as an argument. If no argument is supplied Yii::$app->getRequest()->getUserIP() is used.

//Along with free DB
$location = Yii::$app->geoip->lookupLocation();
$countryCode = Yii::$app->geoip->lookupCountryCode();
$countryName = Yii::$app->geoip->lookupCountryName();

Location attributes:

$location->countryCode //Available in both Country and City DB
$location->countryName //Available in both Country and City DB
$location->continentCode //Available in both Country and City DB
$location->continentName //Available in both Country and City DB
$location->city //Available in only City DB
$location->postalCode //Available in only City DB
$location->latitude //Available in only City DB
$location->longitude //Available in only City DB
$location->timeZone //Available in only City DB