andreyv/yii2-ip-ratelimiter

允许访客客户端使用其IP作为标识符进行速率限制。

安装数: 41,762

依赖关系: 1

建议者: 0

安全: 0

星标: 2

关注者: 1

分支: 11

类型:yii2-module

2.3.1 2023-01-18 12:16 UTC

This package is not auto-updated.

Last update: 2024-09-25 19:42:01 UTC


README

Yii2 IP Rate Limiter

yii2-ip-ratelimiter

允许访客客户端使用其IP作为标识符进行速率限制。

安装

通过composer安装此扩展是首选方式。

运行以下命令之一:

php composer.phar require andreyv/yii2-ip-ratelimiter "2.*"

或者

"andreyv/yii2-ip-ratelimiter": "2.*"

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

使用方法

修改您想要进行速率限制的控制器的行为方法

public function behaviors()
{
    $behaviors = parent::behaviors();
    $behaviors['rateLimiter'] = [
        // Use class
        'class' => \andreyv\ratelimiter\IpRateLimiter::class,

        // The maximum number of allowed requests
        'rateLimit' => 100,

        // The time period for the rates to apply to
        'timePeriod' => 600,

        // Separate rate limiting for guests and authenticated users
        // Defaults to false
        // - false: use one set of rates, whether you are authenticated or not
        // - true: use separate ratesfor guests and authenticated users
        'separateRates' => true,

        // Whether to return HTTP headers containing the current rate limiting information
        'enableRateLimitHeaders' => false,

        // Array of actions on which to apply ratelimiter, if empty - applies to all actions
        'actions' => ['index'],

        // Allows to skip rate limiting for test environment
        'testMode' => true,
        // Defines whether proxy enabled, list of headers getting from request ipHeaders. By default ['X-Forwarded-For']
        'proxyEnabled' => false
    ];
    return $behaviors;
}

从ethercreative/yii2-ip-ratelimiter分支而来。