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

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

yidas/client-ip
===============

Get client IP with safe and coincident way from server even behind Proxy or Load-Balancer

1.0.0(8y ago)2386.1k↓30.8%10BSD-3-ClausePHP

Since Sep 5Pushed 6mo ago2 watchersCompare

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

READMEChangelog (1)DependenciesVersions (3)Used By (0)

 [ ![](https://camo.githubusercontent.com/703a3ff7b5b3b598396dbb36bd62a2ed58a06175d7acf428d20a0c56cb8b5b6b/68747470733a2f2f7777772e7068702e6e65742f696d616765732f6c6f676f732f7068702d6c6f676f2d77686974652e737667) ](https://www.php.net/)

*php* Client IP
===============

[](#php-client-ip)

Get client IP with safe and coincident way from server even behind Proxy or Load-Balancer.

[![Latest Stable Version](https://camo.githubusercontent.com/9a990329386941b1d86f201303e8779de0d1dfbc7be074c41dc0e271493f4db5/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636c69656e742d69702f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/client-ip)[![License](https://camo.githubusercontent.com/4786ebe37175bed2828309d54e1d5f4a66c384df254724044756d06f045fb8b7/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636c69656e742d69702f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/client-ip)[![Total Downloads](https://camo.githubusercontent.com/f2d6b2e06f3d3a74a51c9b0e4f579f257e30befdd9aa90bbe8a6f4b636f2dede/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636c69656e742d69702f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/client-ip)[![Monthly Downloads](https://camo.githubusercontent.com/e20ff08092679a38779568cc797631a648c50037d0c75c1d4f17d571a65d7e78/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636c69656e742d69702f642f6d6f6e74686c793f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/client-ip)

Real IP implement on Web application, which solve the problem that the server receiving requests through trust proxies or load-balancers without Transparent-Mode.

---

DEMONSTRATION
-------------

[](#demonstration)

```
echo ClientIP::get();
ClientIP::config([
    'proxyIPs' => ['192.168.0.0/16', '172.217.3.11'],
    'headerKeys' => ['HTTP_X_FORWARDED_FOR']
    ]);
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.

```

---

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

[](#installation)

Run Composer in your project:

```
composer require yidas/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'],
   ]);
```

AttributeTypeDescriptionproxyIPs arrayTrust Proxies' IP list, which support subnet mask for each IP set.headerKeysarrayHeader Key list for IP Forward.---

DISCUSSION
----------

[](#discussion)

### Implement from Web Server

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

The another way to fetch real IP is implemnet from 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)

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance46

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community11

Small or concentrated contributor base

Maturity64

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

Unknown

Total

1

Last Release

3178d ago

### Community

Maintainers

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

---

Top Contributors

[![yidas](https://avatars.githubusercontent.com/u/12604195?v=4)](https://github.com/yidas "yidas (10 commits)")

---

Tags

ipload-balancerphpproxyreal-iptrust-proxiesIPreal ipclient ipproxy iploadbalancer ip

### Embed Badge

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

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

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[s1lentium/iptools

PHP Library for manipulating network addresses (IPv4 and IPv6)

2446.2M24](/packages/s1lentium-iptools)[zhuzhichao/ip-location-zh

get the ip's location info with Chinese

617212.5k11](/packages/zhuzhichao-ip-location-zh)[markrogoyski/ipv4-subnet-calculator

Network calculator for subnet mask and other classless (CIDR) network information.

177813.7k6](/packages/markrogoyski-ipv4-subnet-calculator)[rlanvin/php-ip

IPv4/IPv6 manipulation library for PHP

180738.8k11](/packages/rlanvin-php-ip)[longman/ip-tools

PHP IP Tools for manipulation with IPv4 and IPv6

147245.6k6](/packages/longman-ip-tools)

PHPackages © 2026

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