dpodium/yii2-geoip-city-db

Yii2 组件,允许轻松使用 MaxMind 免费数据库。

安装数量: 11,984

依赖项: 0

建议者: 0

安全: 0

星标: 2

关注者: 5

分支: 0

公开问题: 0

语言:Shell

类型:yii2-extension

0.48 2024-06-27 04:03 UTC

README

Yii2 组件,允许轻松使用 MaxMind 免费数据库。

基于 phiphi1992/Yii2-GeoIP 包,由 Phi Hoang Xuan 开发。

安装

通过以下方式安装此扩展:通过 composer

运行以下命令之一:

php composer.phar require dpodium/yii2-geoip-city-db "~0.2"

或者将以下内容添加到你的 composer.json 文件的 require 部分:

"dpodium/yii2-geoip-city-db "~0.2"

组件设置

扩展安装完成后,只需按照以下方式修改你的应用程序配置:

return [
    'components' => [
    ...
        'geoip' => [
                   'class' => 'dpodium\yii2\geoip\components\CGeoIP',
               ],
        ...
    ],
    ...
];

如果只需要查询部分国家数据,可以使用 yii2-geoip,它比此扩展的仓库大小更轻,请参阅 dpodium/yii2-geoip

有关数据可用性的更多信息,请参阅以下内容。

使用方法

所有方法都接受一个 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