ethercreative/yii2-ip-ratelimiter

允许访客客户端被速率限制,使用其IP地址作为标识符。

1.0 2016-04-29 16:22 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:58:42 UTC


README

Yii2 IP Rate Limiter

yii2-ip-ratelimiter

允许访客客户端被速率限制,使用其IP地址作为标识符。

安装

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

运行以下命令之一

php composer.phar require ethercreative/yii2-ip-ratelimiter "1.*"

"ethercreative/yii2-ip-ratelimiter": "1.*"

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

使用方法

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

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

		// 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 true
		// - false: use one set of rates, whether you are authenticated or not
		// - true: use separate ratesfor guests and authenticated users
		'separateRates' => false,

		// Whether to return HTTP headers containing the current rate limiting information
		'enableRateLimitHeaders' => false,
	];
	return $behaviors;
}