perfectpanel/yii2-geoip
Composer 安装命令:
composer require perfectpanel/yii2-geoip
包简介
Yii 2 GeoIP extension. Returns country, city, lat, lng of current or specified IP (uses MaxMind's GeoIP2 databases)
README 文档
README
Provides information about geographical location of user by IP address.
Currently available:
- Country
- City
- Latitude, Longitude
- Country ISO Code
Install
Run
$ php composer.phar require perfectpanel/yii2-geoip "~1.0"
OR
add to your composer.json
{
"require": {
"perfectpanel/yii2-geoip": "~1.0"
}
}
and run
$ php composer update
Usage
Like component
<?php $config = [ ... 'components' => [ 'geoip' => ['class' => 'perfectpanel\GeoIP\GeoIP'], ] ... ];
somewhere in code
$ip = Yii::$app->geoip->ip(); // current user ip $ip = Yii::$app->geoip->ip("208.113.83.165"); $ip->city; // "San Francisco" $ip->country; // "United States" $ip->location->lng; // 37.7898 $ip->location->lat; // -122.3942 $ip->isoCode; // "US"
Like object directly somewhere in your application
$geoip = new \perfectpanel\GeoIP\GeoIP(); $ip = $geoip->ip("208.113.83.165"); $ip->city; // "San Francisco" $ip->country; // "United States" $ip->location->lng; // 37.7898 $ip->location->lat; // -122.3942 $ip->isoCode; // "US"
Provide a custom database (for example, if you own a licence)
<?php $config = [ ... 'components' => [ 'geoip' => [ 'class' => 'perfectpanel\GeoIP\GeoIP', 'dbPath' => Yii::getAlias('@example/maxmind/database/city.mmdb') ], ] ... ];
This product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com
统计信息
- 总下载量: 1.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-21