dpodium / yii2-geoip
Yii2 组件,允许轻松使用 MaxMind 免费数据库。
2.1.19
2024-06-27 04:03 UTC
Requires
- geoip2/geoip2: ~2.0
- yiisoft/yii2: 2.0.*
- dev-master
- 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
This package is auto-updated.
Last update: 2024-08-27 04:34:56 UTC
README
Yii2 组件,允许轻松使用 MaxMind 免费数据库。
基于 phiphi1992/Yii2-GeoIP 包,由 Phi Hoang Xuan 开发。
安装
安装此扩展的首选方法是通过 composer。
运行以下命令:
php composer.phar require dpodium/yii2-geoip "~2.0.0"
或者将以下内容添加到你的 composer.json
文件的 require 部分:
"dpodium/yii2-geoip": "~2.0.0"
版本 ~2.0.0 差异
版本 ~2.0.0 使用新的 GeoLite2 数据库版本,而不是现在已废弃的 Legacy GeoLite。
数据库可以在以下位置找到: https://dev.maxmind.com/geoip/geoip2/geolite2/
组件配置
扩展安装完成后,只需按照以下方式修改你的应用程序配置:
return [ 'components' => [ ... 'geoip' => [ 'class' => 'dpodium\yii2\geoip\components\CGeoIP', 'support_ipv6' => false, //Default value ], ... ], ... ];
如果需要查询完整的城市数据,还需要要求 yii2-geoip-city-db,请参阅 dpodium/yii2-geoip-city-db。
有关数据可用性的更多信息,请参阅以下内容。
用法
所有方法都接受一个 IP 地址作为参数。如果没有提供参数,则使用 Yii::$app->getRequest()->getUserIP()。
//Along with free DB
$location = Yii::$app->geoip->lookupLocation();
$countryCode = Yii::$app->geoip->lookupCountryCode();
$countryName = Yii::$app->geoip->lookupCountryName();
位置属性
$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