PHPackages                             slam/psr7-get-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. slam/psr7-get-client-ip

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

slam/psr7-get-client-ip
=======================

Retrieve Client IP from a ServerRequestInterface

v1.4.0(6mo ago)28.0k↓40.9%[1 PRs](https://github.com/Slamdunk/psr7-get-client-ip/pulls)MITPHPPHP ~8.4.0 || ~8.5.0CI passing

Since Aug 10Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Slamdunk/psr7-get-client-ip)[ Packagist](https://packagist.org/packages/slam/psr7-get-client-ip)[ Fund](https://paypal.me/filippotessarotto)[ GitHub Sponsors](https://github.com/Slamdunk)[ RSS](/packages/slam-psr7-get-client-ip/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (9)Used By (0)

PSR-7 Get Client Ip for both IPv4 and IPv6
==========================================

[](#psr-7-get-client-ip-for-both-ipv4-and-ipv6)

[![Latest Stable Version](https://camo.githubusercontent.com/f43fd05097f858ed9cdcaa35ebc0e34fdb1b3b579afc51e4a85b4ccccf9d892d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736c616d2f707372372d6765742d636c69656e742d69702e737667)](https://packagist.org/packages/slam/psr7-get-client-ip)[![Downloads](https://camo.githubusercontent.com/8ea6cf5989ccc3afc525848fda0349cc4b4bb180897e0c91783af7a945ae4506/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736c616d2f707372372d6765742d636c69656e742d69702e737667)](https://packagist.org/packages/slam/psr7-get-client-ip)[![CI](https://github.com/Slamdunk/psr7-get-client-ip/actions/workflows/ci.yaml/badge.svg)](https://github.com/Slamdunk/psr7-get-client-ip/actions/workflows/ci.yaml)[![Infection MSI](https://camo.githubusercontent.com/885e35637b54977048a18f29ad6cd3a51fbcb6291c63b7562d9c5fcfc4f22770/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246536c616d64756e6b253246707372372d6765742d636c69656e742d69702532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/Slamdunk/psr7-get-client-ip/master)

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

[](#installation)

`composer require slam/psr7-get-client-ip`

Motivation &amp; Usage
----------------------

[](#motivation--usage)

Knowing the client's IP is needed to distinguish between bad and good actors, and take appropriate countermeasures. In IPv4 protocol it's an easy job (or it should be ):

- If the actor is good, you take its IPv4 and stick its session to it, so to mitigate session hijacking.
- If the actor is bad, you ban its IPv4.

In IPv6 protocol it's a different story though: routers default implementation allow each client to choose and change their IP within the subnet, which is at least `/64`. Rate-limiting and banning must take this into consideration, see

The best approach is still in debate; this library takes the following approach:

- If the actor is good, the full IPv6 ir returned
- If the actor is bad, the `/64` relative subnet is returned

```
$request = new ServerRequest([
    'REMOTE_ADDR' => '1.2.3.4',
]);

var_dump((new Psr7GetClientIp())->forGoodList($request));       // '1.2.3.4'
var_dump((new Psr7GetClientIp())->forNaughtyList($request));    // '1.2.3.4'

$request = new ServerRequest([
    'REMOTE_ADDR' => '2013:b0a7:5d31:fd03:7257:ae71:6cb9:8e1d',
]);

var_dump((new Psr7GetClientIp())->forGoodList($request));       // '2013:b0a7:5d31:fd03:7257:ae71:6cb9:8e1d'
var_dump((new Psr7GetClientIp())->forNaughtyList($request));    // '2013:b0a7:5d31:fd03::/64'
```

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance79

Regular maintenance activity

Popularity26

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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 ~201 days

Total

5

Last Release

207d ago

PHP version history (4 changes)v1.0.0PHP ~8.1.0 || ~8.2.0

v1.1.0PHP ~8.2.0 || ~8.3.0

v1.2.0PHP ~8.3.0 || ~8.4.0

v1.4.0PHP ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/50348?v=4)[Sahn Lam](/maintainers/Slam)[@slam](https://github.com/slam)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (238 commits)")[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (11 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/slam-psr7-get-client-ip/health.svg)

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

###  Alternatives

[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

343121.4M79](/packages/google-cloud-core)[aimeos/aimeos-base

Aimeos base layer for abstracting from host environments

2.1k134.0k1](/packages/aimeos-aimeos-base)[phpgt/dom

Modern DOM API.

12412.2M18](/packages/phpgt-dom)[anthropic-ai/sdk

Anthropic PHP SDK

129134.7k5](/packages/anthropic-ai-sdk)[jaxon-php/jaxon-core

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

73142.3k25](/packages/jaxon-php-jaxon-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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