degordian/yii2-geofencing

基于访问者地理位置允许或拒绝访问的Yii2 ActionFilter

安装: 84

依赖: 0

建议者: 0

安全: 0

星星: 2

关注者: 9

分支: 2

类型:yii2-extension

v1.0.0 2017-06-13 10:48 UTC

This package is not auto-updated.

Last update: 2024-09-15 02:48:16 UTC


README

一个动作过滤器,允许您根据访问者的位置允许或拒绝动作。

安装

安装此扩展的首选方法是通过composer

运行以下命令之一:

composer require --prefer-dist degordian/yii2-geofencing "~1.0"

或者

"degordian/yii2-geofencing": "~1.0"

将以下内容添加到您的composer.json文件的require部分。

使用方法

一旦安装了扩展,将其添加到您的控制器中

  public function behaviors() {
    return [
      'class' => GeoIpAccessControl::class,
      'isoCodes' => ['HR', 'SI', 'RS'], //ISO 3166-1 alpha-2 two letter country code
      'filterMode' => GeoIpFilterMode::ALLOW, //allows only if you are listed in isoCodes,
      #'filterMode' => GeoIpFilterMode::DENY //allows only if you are not listed in isoCodes
      'getIp' => function() {
        //you can provide a custom function used to get the clients IP
        //defaults to Yii::$app->request->getUserIP()
      },
      'getIsoCode' => function($ip) {
        //you can provide a custom function used to get the iso code from the clients IP
        //by default uses lysenkobv/yii2-geoip
      },
      'message' => 'The message to display if the content is denied'
    ]
  }

由于它扩展了ActionFilter,您可以使用'only'和'except'来精确调整地理围栏标准