zertex / yii2-zx-geoip-country
Yii 2 GeoIP 扩展。返回当前或指定 IP 的国家(使用 MaxMind 的 GeoIP2 数据库)
1.0.2
2017-03-23 08:32 UTC
Requires
- php: >=5.4.0
- maxmind-db/reader: ~1.0
- yiisoft/yii2: >=2.0.0
- zertex/yii2-zx-country-db: *
Requires (Dev)
- phpunit/phpunit: ~4.4
This package is not auto-updated.
Last update: 2024-09-28 20:09:19 UTC
README
通过 IP 地址提供关于用户国家的信息。
当前可用
- 国家
- 国家 ISO 代码
安装
运行
$ php composer.phar require zertex/yii2-zx-geoip-country "~1.0"
或者
添加到你的 composer.json
{ "require": { "zertex/yii2-zx-geoip-country": "~1.0" } }
并运行
$ php composer update
使用方法
像组件一样
<?php $config = [ ... 'components' => [ 'geoip' => ['class' => 'zertex\GeoIP\GeoIP'], ] ... ];
在代码中的某处
$ip = Yii::$app->geoip->ip(); // current user ip $ip = Yii::$app->geoip->ip("111.111.111.111"); $ip->country; // "United States"
直接在应用中的某处像对象一样使用
$geoip = new \zertex\GeoIP\GeoIP(); $ip = $geoip->ip("111.111.111.111"); $ip->country; // "United States"
此产品包括由 MaxMind 创建的 GeoLite2 数据,可通过 http://www.maxmind.com 获取