PHPackages                             harmlessprince/superban - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. harmlessprince/superban

ActiveLibary[Security](/categories/security)

harmlessprince/superban
=======================

Ban client completely for a period of time after they have exhausted there request

1.0.0(2y ago)512MITPHP ^8.1

Since Dec 20Compare

[ Source](https://github.com/harmlessprince/laravel-superban)[ Packagist](https://packagist.org/packages/harmlessprince/superban)[ RSS](/packages/harmlessprince-superban/feed)WikiDiscussions Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

Superban Package
================

[](#superban-package)

 SuperBan is a Laravel middleware package that helps you manage and control the rate of incoming requests to your application. It can be useful in scenarios where you want to prevent abuse, limit the number of requests from a specific route or group of route the client and enforce temporary bans when necessary.

The package is designed using the *Token Bucket Algorithm*.

Below is a brief explanation of the algorithm from Google

`The token bucket is an algorithm used in packet-switched and telecommunications networks. It can be used to check that data transmissions, in the form of packets, conform to defined limits on bandwidth and burstiness (a measure of the unevenness or variations in the traffic flow). `

In the concept of this Superban package, below is a brief explanation of how it works.

The middleware has a first parameter called maximumRequest. This maximum request parameter represents our tokens and is associated with a key in the cache. So each incoming request into our server consumes a token; if no tokens are left, the request is rejected. If the client tries to hit the same endpoint again within the interval specified for the token to be used, the client is then banned from the specific route for the duration of the ban time supplied.

`Note: All supplied parameters are expected to be in minutes.`

Installation
------------

[](#installation)

```
composer require harmlessprince/superban
```

Once the Superban package is installed, the package will be autoloaded, this package is built with php 8.1. Any Laravel version that supports PHP 8.1 will autoload the package; however, if you want to add it yourself.

Open up `config/app.php` and add the following to the `providers` key.

```
'providers' => [
    // other service providers
    Harmlessprince\SuperBan\SuperBanServiceProvider::class,
],
```

Configuration
-------------

[](#configuration)

The default cache driver is `file`; you can change it to any laravel supported cache driver in your environment variable like below

```
SUPER_BAN_CACHE_DRIVER=redis
```

You can publish the configuration file using this command:

```
php artisan vendor:publish --provider="Harmlessprince\SuperBan\SuperBanServiceProvider" --tag=superban-config
```

A configuration-file named `superban.php` with defaults will be placed in your `config` directory:

```
