dpodium / yii2-geoip
Yii2 Component to allow for easy usage of the MaxMind Free dbs.
Installs: 25 890
Dependents: 2
Suggesters: 0
Security: 0
Stars: 8
Watchers: 6
Forks: 3
Open Issues: 2
Type:yii2-extension
Requires
- geoip2/geoip2: ~2.0
- yiisoft/yii2: 2.0.*
- dev-master
- 2.1.20
- 2.1.19
- 2.1.18
- 2.1.17
- 2.1.16
- 2.1.15
- 2.1.14
- 2.1.13
- 2.1.12
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1
- 2.0.34
- 2.0.33
- 2.0.32
- 2.0.31
- 2.0.30
- 2.0.29
- 2.0.28
- 2.0.27
- 2.0.26
- 2.0.25
- 2.0.24
- 2.0.23.1
- 2.0.23
- 2.0.22
- 2.0.21
- 2.0.20
- 2.0.19
- 2.0.18
- 2.0.17
- 2.0.16
- 2.0.15
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3
- 1.2
- 1.1
- 1.0.1
- 1.0
- dev-hotfix-chingyen-sc-252924-v20241029
This package is auto-updated.
Last update: 2024-11-01 09:25:40 UTC
README
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 "~2.0.0"
or add
"dpodium/yii2-geoip": "~2.0.0"
to the require section of your composer.json
file.
Version ~2.0.0 Difference
Version ~2.0.0 uses the new GeoLite2 version of the db instead of the Legacy GeoLite which is now deprecated.
Database can be found here: https://dev.maxmind.com/geoip/geoip2/geolite2/
Component Setup
Once the extension is installed, simply modify your application configuration as follows:
return [ 'components' => [ ... 'geoip' => [ 'class' => 'dpodium\yii2\geoip\components\CGeoIP', 'support_ipv6' => false, //Default value ], ... ], ... ];
If querying full City data is required, yii2-geoip-city-db must be required as well, see dpodium/yii2-geoip-city-db.
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