PHPackages                             php-core/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. php-core/client-ip

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

php-core/client-ip
==================

0144PHP

Since Aug 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/php-core/client-ip)[ Packagist](https://packagist.org/packages/php-core/client-ip)[ RSS](/packages/php-core-client-ip/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

client-ip
=========

[](#client-ip)

Get client IP in PHP even behind CloudFlare, Proxy or Load-Balancer.
====================================================================

[](#get-client-ip-in-php-even-behind-cloudflare-proxy-or-load-balancer)

---

Thanks to  for the idea of making a package for this and also providing a base structure for the class.

INSTALLATION
------------

[](#installation)

Run Composer in your project:

```
composer require php-core/client-ip

```

Then initialize it at the bootstrap of application such as `config` file:

```
require __DIR__ . '/vendor/autoload.php';
ClientIP::config([
   'proxyIPs' => ['192.168.0.0/16']
]);
```

---

CONFIGURATION
-------------

[](#configuration)

Example configuration:

```
ClientIP::config([
   'proxyIPs' => ['192.168.0.0/16', '172.217.2.89'],
   'headerKeys' => ['HTTP_X_FORWARDED_FOR'],
]);
```

AttributeTypeDescriptionproxyIPsarrayTrust Proxies' IP list, which support subnet mask for each IP set.headerKeysarrayHeader Key list for IP Forward.disableCacheboolDisable runtime cache.---

Examples
--------

[](#examples)

```
echo ClientIP::get();
ClientIP::config([
    'proxyIPs' => ['192.168.0.0/16', '172.217.3.11'],
    'headerKeys' => ['HTTP_X_FORWARDED_FOR']
]);
echo ClientIP::get();
```

By default, the system caches the IP in runtime, to disable it, (for example for amphp's web-server), use `disableCache`:

```
ClientIP::config([
    'disableCache' => true
]);
echo ClientIP::get();
```

If the client IP is `203.169.1.37`, there are some connection situation for demonstrating referring by above sample code:

### Load-Balancer normal network

[](#load-balancer-normal-network)

your server is behind a Load-Balencer and in a private network.

ClientLoad-BalancerServer203.169.1.37 →172.217.2.88 ↓192.168.0.10 →192.168.4.100```
ClientIP::config([
    'proxyIPs' => true
]);
```

Setting `proxyIPs` as `true` means all requests are go through Load-balancer, which will always get forward IP, same as above setting:

```
ClientIP::config([
    'proxyIPs' => ['0.0.0.0/32']
]);
```

**The result from the server:**

```
192.168.0.10 //Before setting the config
203.169.1.37 //After setting the config, get the forward IP

```

### Proxy optional network

[](#proxy-optional-network)

If your server is in public network, not only receives requests directly, but also supports trust proxies for going through:

ClientProxyServerWay 1203.169.1.37 →172.217.4.100Way 2203.169.1.37 →172.217.2.89 ↓172.217.3.11 →172.217.4.100```
ClientIP::config([
    'proxyIPs' => ['172.217.3.11']
]);
```

**The result from the server**

- Way 1: Client connect to server directly:

```
203.169.1.37 //Before setting the config
203.169.1.37 //The request IP is not from proxyIPs, so identify as a Client.

```

- Way 2: Client connect to server through Proxy:

```
172.217.3.11 //Before setting the config
203.169.1.37 //The request IP comes from proxyIPs, get the forward IP.

```

---

DISCUSSION
----------

[](#discussion)

### Implement from Web Server

[](#implement-from-web-server)

Another way to fetch real IP is to implement it on the web server side:

- [Nginx: ngx\_http\_realip\_module](http://nginx.org/en/docs/http/ngx_http_realip_module.html)
- [Apache: mod\_remoteip](https://httpd.apache.org/docs/trunk/mod/mod_remoteip.html)

Licence
=======

[](#licence)

MIT

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/103283996?v=4)[PHP Core](/maintainers/php-core)[@php-core](https://github.com/php-core)

---

Top Contributors

[![php-core](https://avatars.githubusercontent.com/u/103283996?v=4)](https://github.com/php-core "php-core (1 commits)")

### Embed Badge

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

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

###  Alternatives

[kryptonit3/counter

Hit counter for your pages.

8724.1k](/packages/kryptonit3-counter)

PHPackages © 2026

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