slavkluev/yii2-ip2location

A Yii2 extension allows you to get the user's location by IP address. Use a free Ip2Location LITE database. Auto-update database.

v1.0.2 2020-07-22 02:26 UTC

This package is auto-updated.

Last update: 2024-04-22 11:01:42 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

A Yii2 extension allows you to get the user's location by IP address. Use a free Ip2Location LITE database. Auto-update database.

Parameters

  • dbFile Path to database file. Default: Yii::getAlias('@vendor/slavkluev/yii2-ip2location/database/DB.BIN')
  • downloadToken Unique download token to download IP2Location databases.
  • downloadCode Database code for downloading. Default: DB1LITEBIN.
  • mode Caching mode (one of FILE_IO, MEMORY_CACHE, or SHARED_MEMORY). Default: \IP2Location\Database::FILE_IO.
  • defaultFields Field(s) to return. Default: \IP2Location\Database::ALL.

Install

Package is available on Packagist, you can install it using Composer.

composer require slavkluev/yii2-ip2location

Usage

Add ip2location component to your configuration file.

'components' => [
    'ip2location' => [
      'class' => \slavkluev\Ip2Location\Ip2Location::class,
      'downloadToken' => 'secret',
    ],
],

Get information on custom IP address:

print_r(Yii::$app->ip2location->ip('127.0.0.1'));

Get information on user IP address:

print_r(Yii::$app->ip2location->ip());

Update

In order to update the database, a token is required. You can use the free database: IP2Location LITE BIN Data

To update the database, use the command:

$ yii ip2location/update

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email slavkluev@yandex.ru instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.