PHPackages                             juanpagfe/slim-ip-filter - 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. [Framework](/categories/framework)
4. /
5. juanpagfe/slim-ip-filter

AbandonedArchivedLibrary[Framework](/categories/framework)

juanpagfe/slim-ip-filter
========================

A Slim middleware to restrict/allow ip addresses that will access to your routes

0.1.0(8y ago)084GPL-2.0+PHPPHP &gt;=5.5.0

Since Dec 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/juanpagfe/slim-ip-filter)[ Packagist](https://packagist.org/packages/juanpagfe/slim-ip-filter)[ RSS](/packages/juanpagfe-slim-ip-filter/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (5)Versions (2)Used By (0)

Slim Framework IP Filter
========================

[](#slim-framework-ip-filter)

A slim middleware to filter ip addresses that will access to your routes. It internally uses `Ip` Validator of [Respect/Validation](https://github.com/Respect/Validation/) and [rka-ip-address-middleware](https://github.com/akrabat/rka-ip-address-middleware). Is based on [slim-restrict-route](https://github.com/DavidePastore/Slim-Restrict-Route)

Install
-------

[](#install)

Via Composer

```
$ composer require juanpagfe/slim-ip-filter
```

Requires Slim 3.0.0 or newer.

Usage
-----

[](#usage)

You have to register also the [`RKA\Middleware\IpAddress`](https://github.com/akrabat/rka-ip-address-middleware) middleware to correctly read the ip address. In most cases you want to register `Jpgfe\Slim\IpFilter` for a single route, however, as it is middleware, you can also register it for all routes.

### Register per route

[](#register-per-route)

```
$app = new \Slim\App();

$app->add(new RKA\Middleware\IpAddress());

$options = array(
    array(
        'ip' => '192.*.*.*',
        'allow' => false
        )
);

$app->get('/api/myEndPoint',function ($req, $res, $args) {
  //Your amazing route code
})->add(new \Jpgfe\Slim\IpFilter\RestrictRoute($options));

$app->run();
```

### Register for all routes

[](#register-for-all-routes)

```
$app = new \Slim\App();

$app->add(new RKA\Middleware\IpAddress());

$options = array(
    array(
        'ip' => '192.*.*.*',
        'allow' => false
        )
);

// Register middleware for all routes
// If you are implementing per-route checks you must not add this
$app->add(new \Jpgfe\Slim\IpFilter\RestrictRoute($options));

$app->get('/foo', function ($req, $res, $args) {
  //Your amazing route code
});

$app->post('/bar', function ($req, $res, $args) {
  //Your amazing route code
});

$app->run();
```

Ip address
----------

[](#ip-address)

You can restrict route using a different value of `ip` in the `options` given to `\RestrictRoute`:

- any of the filters provided by PHP regarding `FILTER_VALIDATE_IP` (e.g.: `FILTER_FLAG_NO_PRIV_RANGE`);
- asterisk (`*`) to filter ip that are in the given subnet (e.g.: `192.*`);
- ranges (`-`) to filter ip that are in the given range (e.g.: `192.168.0.0-192.168.255.255`);
- single ip (e.g.: `192.168.0.1-192.168.0.1`);
- array of ranges to filter ip (e.g.: `array('192.0.0.0-192.255.255.255', '178.0.0.*')`).

You can find more syntax information on the `Ip` validator [documentation](https://github.com/Respect/Validation/blob/master/docs/Ip.md) and in its [Unit Test class](https://github.com/Respect/Validation/blob/master/tests/unit/Rules/IpTest.php).

Testing
-------

[](#testing)

```
$ phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Juan Pablo Garcia](https://github.com/juanpagfe)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3080d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dee4d339b8a98ebb1fa909a438d60665559316f35482ba852de3a2f689fd1cfd?d=identicon)[juanpagfe](/maintainers/juanpagfe)

---

Top Contributors

[![juanpagfe](https://avatars.githubusercontent.com/u/773156?v=4)](https://github.com/juanpagfe "juanpagfe (1 commits)")

---

Tags

filteripphpslimslim-frameworkmiddlewareframeworkaddressslimIPrestrictionrestrictallowallowance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/juanpagfe-slim-ip-filter/health.svg)

```
[![Health](https://phpackages.com/badges/juanpagfe-slim-ip-filter/health.svg)](https://phpackages.com/packages/juanpagfe-slim-ip-filter)
```

###  Alternatives

[davidepastore/slim-restrict-route

A Slim middleware to restrict ip addresses that will access to your routes

2220.6k1](/packages/davidepastore-slim-restrict-route)[slim/csrf

Slim Framework 4 CSRF protection PSR-15 middleware

3512.1M94](/packages/slim-csrf)[davidepastore/slim-validation

A slim middleware for validation based on Respect/Validation

171223.7k3](/packages/davidepastore-slim-validation)[slim/http-cache

Slim Framework HTTP cache middleware and service provider

1242.9M27](/packages/slim-http-cache)[pavlakis/slim-cli

Making a mock GET request through the CLI and enabling the same application entry point on CLI scripts.

3691.9k3](/packages/pavlakis-slim-cli)[davidepastore/slim-config

A slim middleware to read configuration from different files based on hassankhan/config

338.9k1](/packages/davidepastore-slim-config)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
