PHPackages                             davidepastore/slim-restrict-route - 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. davidepastore/slim-restrict-route

ActiveLibrary[Framework](/categories/framework)

davidepastore/slim-restrict-route
=================================

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

v0.3.1(7y ago)2220.6k↓39.6%81GPL-2.0+PHPPHP &gt;=5.5.0CI failing

Since Apr 25Pushed 5y ago3 watchersCompare

[ Source](https://github.com/DavidePastore/Slim-Restrict-Route)[ Packagist](https://packagist.org/packages/davidepastore/slim-restrict-route)[ RSS](/packages/davidepastore-slim-restrict-route/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (7)Used By (1)

Slim Framework Restrict Route
=============================

[](#slim-framework-restrict-route)

[![Latest version](https://camo.githubusercontent.com/248ef58914945809d40a456174404f2aa881cd331d367268dbd994f7f75f8623/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f446176696465506173746f72652f536c696d2d52657374726963742d526f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/davidepastore/slim-restrict-route)[![Build Status](https://camo.githubusercontent.com/7c2384a5f4880946bb16919a0704235a4a92bd8e33a4221d7b92545979acccdf/68747470733a2f2f7472617669732d63692e6f72672f446176696465506173746f72652f536c696d2d52657374726963742d526f7574652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/DavidePastore/Slim-Restrict-Route)[![Coverage Status](https://camo.githubusercontent.com/9a20ce05b1858fa9df97941c5a96a0a8cf4cd1c5458c8d27d4832d4289cfd300/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f446176696465506173746f72652f536c696d2d52657374726963742d526f7574652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidePastore/Slim-Restrict-Route/code-structure)[![Quality Score](https://camo.githubusercontent.com/33d572dcd5f25d2df6db79c1a638aca835d0b005e04b13bdaa8ffb181caa0185/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f646176696465706173746f72652f536c696d2d52657374726963742d526f7574652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/DavidePastore/Slim-Restrict-Route)[![Total Downloads](https://camo.githubusercontent.com/1953bcc835c16d900256f211b401f100c62277945e04dd5bd43f919481eaa809/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646176696465706173746f72652f736c696d2d72657374726963742d726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/davidepastore/slim-restrict-route)[![PSR2 Conformance](https://camo.githubusercontent.com/767acfefd6119c42181e8edf035be13d23f6e21bd9bfed3d0d9001fba58f5b43/68747470733a2f2f7374796c6563692e696f2f7265706f732f35373037313136372f736869656c64)](https://styleci.io/repos/57071167/)

A slim middleware to restrict 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).

Install
-------

[](#install)

Via Composer

```
$ composer require davidepastore/slim-restrict-route
```

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 `DavidePastore\Slim\RestrictRoute` 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(
  'ip' => '192.*.*.*'
);

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

$app->run();
```

### Register for all routes

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

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

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

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

// Register middleware for all routes
// If you are implementing per-route checks you must not add this
$app->add(new \DavidePastore\Slim\RestrictRoute\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)

- [Davide Pastore](https://github.com/davidepastore)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.2% 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

Every ~196 days

Total

5

Last Release

2886d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11a9e9c18e06a1827a69e0b5e7c4644e1f937f70463ff88b25b76b172be5e769?d=identicon)[DavidePastore](/maintainers/DavidePastore)

---

Top Contributors

[![DavidePastore](https://avatars.githubusercontent.com/u/1949364?v=4)](https://github.com/DavidePastore "DavidePastore (20 commits)")[![bennyvdhoogen](https://avatars.githubusercontent.com/u/70586325?v=4)](https://github.com/bennyvdhoogen "bennyvdhoogen (1 commits)")

---

Tags

ipmiddlewarephprestrictedslim-frameworkmiddlewareframeworkaddressslimIPrestrictionrestrict

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/davidepastore-slim-restrict-route/health.svg)

```
[![Health](https://phpackages.com/badges/davidepastore-slim-restrict-route/health.svg)](https://phpackages.com/packages/davidepastore-slim-restrict-route)
```

###  Alternatives

[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)[geggleto/psr7-recaptcha

113.2k](/packages/geggleto-psr7-recaptcha)

PHPackages © 2026

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