PHPackages                             netglue/realip-helpers - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. netglue/realip-helpers

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

netglue/realip-helpers
======================

PSR-15 Middleware for detecting the real client ip amongst other helpers.

2.0.1(5y ago)337.5k1MITPHPPHP &gt;=7.3CI failing

Since Aug 20Pushed 5y ago1 watchersCompare

[ Source](https://github.com/netglue/RealIP-Helpers)[ Packagist](https://packagist.org/packages/netglue/realip-helpers)[ RSS](/packages/netglue-realip-helpers/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (11)Versions (5)Used By (1)

Helpers for retrieving the real client IP in Laminas/Mezzio Projects
====================================================================

[](#helpers-for-retrieving-the-real-client-ip-in-laminasmezzio-projects)

[![Latest Stable Version](https://camo.githubusercontent.com/bb2604b27893310f1326a4569221606ac65c12898e5aebaeaa34e893001157ff/68747470733a2f2f706f7365722e707567782e6f72672f6e6574676c75652f7265616c69702d68656c706572732f76657273696f6e)](https://packagist.org/packages/netglue/realip-helpers)[![codecov](https://camo.githubusercontent.com/8b9466de5c9f4f53a2faf4757b9990b9a129a4ee726265bba9be28236322515c/68747470733a2f2f636f6465636f762e696f2f67682f6e6574676c75652f5265616c49502d48656c706572732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/netglue/RealIP-Helpers)[![PHPUnit Test Suite](https://github.com/netglue/RealIP-Helpers/workflows/PHPUnit%20Test%20Suite/badge.svg)](https://github.com/netglue/RealIP-Helpers/workflows/PHPUnit%20Test%20Suite/badge.svg)

Why?
----

[](#why)

I put this together to scratch an itch - I typically write server-side apps using Mezzio or Laminas MVC *(Formerly Expressive and Zend Framework)* and there's an existing middleware implementation [akrabat/ip-address-middleware](https://github.com/akrabat/ip-address-middleware), that already solves the problem of getting the remote address, optionally from common proxy headers with PSR-7/PSR-15 middleware.

The problem I had with that package is that it requires an array of trusted proxies in order to perform searches of those headers, so if your app is behind a load balancer, and it's IP might change, this means that updating your config is a pain, particularly if you're using the component in multiple projects on the same environment. Also, this package introduces the concept of a trusted header, i.e. if you've got an upstream proxy you can guarantee will send you a header with the remote address, and you're confident your proxy cannot be circumvented, then you can ignore the idea of trusted proxies and just use that header. Furthermore, I wanted the convenience of default configuration and DI factories for the middleware and helpers. You may also want to checkout this too: [middlewares/client-ip](https://github.com/middlewares/client-ip).

Install
-------

[](#install)

Install with Composer using `"netglue/realip-helpers"`

Configure
---------

[](#configure)

Without any additional configuration, the helper(s) will simply return whatever `$_SERVER['REMOTE_ADDR']` reports *(But sanitised and validated as an actual IP address)*. The reason you're looking at this is probably because `REMOTE_ADDR` doesn't cut it… Options are detailed in [`./src/ConfigProvider.php`](https://github.com/netglue/RealIP-Helpers/blob/master/src/ConfigProvider.php) and repeated below. The values are the defaults.

```
return [
    'proxy_headers' => [
        // When figuring out the client IP, should common proxy headers be checked?
        'checkProxyHeaders' => false,
        // If your app is firewalled, and you're sure you can trust that, say,
        // Cloud Flare is sending you the client IP in the header 'CF-Connecting-IP', you can add that here
        // and it will always be used
        'trustedHeader' => null,
        // If your app is on a private network and REMOTE_ADDR is always the load balancer ip, you could say
        // that REMOTE_ADDR is always a trusted proxy
        'remoteAddressIsTrustedProxy' => false,
        // You can provide an array of IP addresses (v4 or v6) of proxies that you trust. These will be eliminated as
        // potential client IP addresses
        'trustedProxies' => [],
        // If you provide a non-empty array of proxy headers to inspect, only these headers will be checked,
        // overriding the defaults. If you know that your proxy/loadbalancer only sends X-Forwarded-For, you could
        // put just that one in here. By default, a number of headers are inspected:
        'proxyHeadersToInspect' => [],
    ],
];
```

MVC Usage
---------

[](#mvc-usage)

Config should be injected automatically if you are using Laminas component installer, so it's just a case of altering config values for your environment if appropriate and then issuing a `$ip = $this->clientIp()` from a controller method to retrieve the remote IP address.

Mezzio Usage
------------

[](#mezzio-usage)

Add `NetglueRealIP\Middleware\IpAddress::class` to your pipeline, and your request will contain the attribute `'ip_address'`, i.e. `$request->getAttribute('ip_address')`. You can change the name of the attribute at construction time if you are not using a DI container, or if you are, by aliasing the class to a different factory.

Test
----

[](#test)

`cd` to wherever the module is installed, issue a `composer install` followed by a `composer test`.

Contributions
-------------

[](#contributions)

PR's are welcomed. Please write tests for new features.

Support
-------

[](#support)

You're welcome to file issues, but please understand that finding the time to answer support requests is very limited so there might be a long wait for an answer.

About
-----

[](#about)

[Netglue makes websites and apps in Devon, England](https://netglue.uk). We hope this is useful to you and we’d appreciate feedback either way :)

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

Every ~402 days

Total

3

Last Release

2070d ago

Major Versions

1.0.0 → 2.0.02020-03-31

PHP version history (2 changes)1.0.0PHP &gt;=7.1

2.0.0PHP &gt;=7.3

### Community

Maintainers

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

---

Top Contributors

[![gsteel](https://avatars.githubusercontent.com/u/2803720?v=4)](https://github.com/gsteel "gsteel (18 commits)")

---

Tags

laminaslaminas-mvcmezziomiddlewarepsr-11psr-15zend

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/netglue-realip-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/netglue-realip-helpers/health.svg)](https://phpackages.com/packages/netglue-realip-helpers)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.5k1.5M88](/packages/mcp-sdk)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)[xima/xima-typo3-frontend-edit

Frontend Edit - This extension provides an edit button for editors within frontend content elements.

1414.3k](/packages/xima-xima-typo3-frontend-edit)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

74149.4k30](/packages/jaxon-php-jaxon-core)

PHPackages © 2026

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