PHPackages                             metarush/firewall - 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. metarush/firewall

ActiveLibrary[Security](/categories/security)

metarush/firewall
=================

A firewall for web applications that wants to blacklist/whitelist IP addresses

v2.1.0(1mo ago)42321MITPHPPHP &gt;=7.4

Since Feb 2Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/metarush/firewall)[ Packagist](https://packagist.org/packages/metarush/firewall)[ RSS](/packages/metarush-firewall/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (6)Versions (5)Used By (1)

metarush/firewall
=================

[](#metarushfirewall)

A firewall library that web apps can use to ban IP addresses temporarily or for an extended period of time

---

### Sample Use Case

[](#sample-use-case)

When a user fails an action in your app (e.g., login) for 5 times, this library will lock them temporarily for 15 minutes. After that, they can try again for a maximum of 5 temporary locks. After that, they will be locked for a extended period of 24 hours.

### Summary

[](#summary)

- 5 fails within a 15-minute period = 15-minute temporary lock
- 5 temporary locks = 24-hour lock

Note: These settings can be changed

Install
-------

[](#install)

Install via composer as `metarush/firewall`

Setup
-----

[](#setup)

1. Create a database (with PDO support e.g., MySQL, SQLite).
2. Create tables with these names:

    - `mrfwTempBan`
    - `mrfwExtendedBan`
    - `mrfwWhitelist`
    - `mrfwFailCount`
    - `mrfwBlockCount`

        Note: You can use different table names but these are the default names
3. Each table must have the following fields:

    - `ip` (`STRING` with `46` length )
    - `dateTime` (`STRING` with `19` length)

Use the appropriate column type for your database flavor. E.g., `dateTime`will store dates in `Y-m-d H:i:s` format so use `DATETIME` column type if your database is MySQL.

**Sample create table query for MySQL**

```
CREATE TABLE `tempBan` (
    `ip` VARCHAR(46),
    `dateTime` DATETIME
) ENGINE=MyISAM;

```

Usage with default settings
---------------------------

[](#usage-with-default-settings)

### Init library

[](#init-library)

```
