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.
Installs: 202
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- php: ~7.2
- ext-zip: *
- guzzlehttp/guzzle: ^6.5|^7.0
- ip2location/ip2location-php: ^8.2
- yiisoft/yii2: ^2.0.13.1
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: >=8.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-12-22 12:15:26 UTC
README
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 ofFILE_IO
,MEMORY_CACHE
, orSHARED_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.