PHPackages                             middlewares/client-ip - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. middlewares/client-ip

ActiveLibrary[HTTP &amp; Networking](/categories/http)

middlewares/client-ip
=====================

Middleware to detect the client ip and save it as a request attribute

v2.1.0(1y ago)16661.2k—3%8[1 issues](https://github.com/middlewares/client-ip/issues)8MITPHPPHP ^7.2 || ^8.0CI failing

Since Oct 10Pushed 1y ago3 watchersCompare

[ Source](https://github.com/middlewares/client-ip)[ Packagist](https://packagist.org/packages/middlewares/client-ip)[ Docs](https://github.com/middlewares/client-ip)[ RSS](/packages/middlewares-client-ip/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (8)Versions (17)Used By (8)

middlewares/client-ip
=====================

[](#middlewaresclient-ip)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a1b312749cbd2f4fb7a72de3dcae6cd400ee2aa3b172a97b20f1e6487557b507/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6964646c6577617265732f636c69656e742d69702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/client-ip)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Testing](https://github.com/middlewares/client-ip/workflows/testing/badge.svg)](https://github.com/middlewares/client-ip/workflows/testing/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/d924c0685030b1be2fbd2de359efad7eed646243b1477179ee0d9d3ceeaf43dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6964646c6577617265732f636c69656e742d69702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/middlewares/client-ip)

Middleware to detect the client ip and save it as a request attribute.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2
- A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
- A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)

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

[](#installation)

This package is installable and autoloadable via Composer as [middlewares/client-ip](https://packagist.org/packages/middlewares/client-ip).

```
composer require middlewares/client-ip
```

Usage
-----

[](#usage)

```
$dispatcher = new Dispatcher([
	new Middlewares\ClientIp(),

    function ($request) {
        //Get the client ip
        $ip = $request->getAttribute('client-ip');
    }
]);

$response = $dispatcher->dispatch(new ServerRequest());
```

### proxy

[](#proxy)

This option configures the detection through proxies. The first argument is an array of ips or cidr of the trusted proxies. If it's empty, no ip filtering is made. The second argument is a list of the headers to inspect. If it's not defined, uses the default value `['Forwarded', 'Forwarded-For', 'Client-Ip', 'X-Forwarded', 'X-Forwarded-For', 'X-Cluster-Client-Ip']`. Disabled by default.

```
//Use proxies
$middleware = (new Middlewares\ClientIp())->proxy();

//Trust only some proxies by ip
$middleware = (new Middlewares\ClientIp())->proxy(['10.10.10.10', '10.10.10.11']);

//Trust only some proxies by ip using a specific header
$middleware = (new Middlewares\ClientIp())->proxy(['10.10.10.10', '10.10.10.11'], ['X-Forwarded-For']);

// Trust only some proxies by cidr range
// usefull when you have an autoscaled proxy(like haproxy) in a subnet
$middleware = (new Middlewares\ClientIp())->proxy(['192.168.0.0/16', '10.0.0.0/8']);
```

### attribute

[](#attribute)

By default, the ip is stored in the `client-ip` attribute of the server request. This options allows to modify that:

```
//Save the ip in the "ip" attribute
$middleware = (new Middlewares\ClientIp())->attribute('ip');
```

---

Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance41

Moderate activity, may be stable

Popularity47

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 81.9% 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 ~205 days

Recently: every ~565 days

Total

16

Last Release

468d ago

Major Versions

v0.7.0 → v1.0.02018-01-27

v1.3.0 → v2.0.02019-12-03

PHP version history (4 changes)v0.1.0PHP ^5.6 || ^7.0

v0.7.0PHP ^7.0

v2.0.0PHP ^7.2

v2.0.1PHP ^7.2 || ^8.0

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/42e0d72f42eb7d84f67e20d28606da42e5a3248ca908b1eadb4366aafeae2561?d=identicon)[filisko](/maintainers/filisko)

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (68 commits)")[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (7 commits)")[![filisko](https://avatars.githubusercontent.com/u/8798694?v=4)](https://github.com/filisko "filisko (3 commits)")[![zsrinivas](https://avatars.githubusercontent.com/u/6435796?v=4)](https://github.com/zsrinivas "zsrinivas (3 commits)")[![martinssipenko](https://avatars.githubusercontent.com/u/598744?v=4)](https://github.com/martinssipenko "martinssipenko (1 commits)")[![mattsah](https://avatars.githubusercontent.com/u/586346?v=4)](https://github.com/mattsah "mattsah (1 commits)")

---

Tags

httpipmiddlewarepsr-15httppsr-7middlewareserverpsr-15IP

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/middlewares-client-ip/health.svg)

```
[![Health](https://phpackages.com/badges/middlewares-client-ip/health.svg)](https://phpackages.com/packages/middlewares-client-ip)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3923.8M126](/packages/mezzio-mezzio)[middlewares/request-handler

Middleware to execute request handlers

451.8M30](/packages/middlewares-request-handler)[middlewares/firewall

Middleware to provide IP filtering

12320.3k2](/packages/middlewares-firewall)[middlewares/fast-route

Middleware to use FastRoute

98205.1k15](/packages/middlewares-fast-route)[middlewares/negotiation

Middleware to implement content negotiation

46458.6k11](/packages/middlewares-negotiation)[middlewares/http-authentication

Middleware to implement Basic and Digest Http authentication

34306.4k2](/packages/middlewares-http-authentication)

PHPackages © 2026

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