https://github.com/ethercreative/yii2-ip-ratelimiter
Allow guest clients to be rate limited, using their IP as the identifier
https://github.com/ethercreative/yii2-ip-ratelimiter
Last synced: 9 months ago
JSON representation
Allow guest clients to be rate limited, using their IP as the identifier
- Host: GitHub
- URL: https://github.com/ethercreative/yii2-ip-ratelimiter
- Owner: ethercreative
- License: mit
- Created: 2016-04-29T15:12:12.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-01-18T12:14:13.000Z (over 3 years ago)
- Last Synced: 2025-08-10T03:56:16.109Z (10 months ago)
- Language: PHP
- Size: 96.7 KB
- Stars: 36
- Watchers: 5
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# yii2-ip-ratelimiter
Allow guest clients to be rate limited, using their IP as the identifier.
## Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require ethercreative/yii2-ip-ratelimiter "1.*"
```
or add
```
"ethercreative/yii2-ip-ratelimiter": "1.*"
```
to the require section of your `composer.json` file.
## Usage
Modify the bahavior method of the controller you want to rate limit
```
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;
}
```