PHPackages                             sinanbekar/cf-restore-visitor-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. sinanbekar/cf-restore-visitor-ip

ActiveLibrary

sinanbekar/cf-restore-visitor-ip
================================

Cloudflare Restore Original Visitor IP

00PHP

Since Jun 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/sinanbekar/cf-restore-visitor-ip)[ Packagist](https://packagist.org/packages/sinanbekar/cf-restore-visitor-ip)[ RSS](/packages/sinanbekar-cf-restore-visitor-ip/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

cf-restore-visitor-ip
=====================

[](#cf-restore-visitor-ip)

Cloudflare Restore Original Visitor IP in PHP

There are mod\_cloudflare(mod\_remoteip),nginx\_realip packages why would we use this ?
---------------------------------------------------------------------------------------

[](#there-are-mod_cloudflaremod_remoteipnginx_realip-packages-why-would-we-use-this-)

mod\_cloudflare hasn't been updated for years. Cloudflare's IP ranges can be change in time (Current ranges are different). mod\_cloudflare is only for Apache server. If you're using shared hosting (and if the server administrator does not configure cloudflare rules) mostly you can't change core configs.

If you have access to server configuration files and have experience configuring them, please check mod\_remoteip(Apache), ngx\_http\_realip\_module(NGINX) first. It should be better to restore the log IP addresses.

[Cloudflare mod\_remoteip Article](https://support.cloudflare.com/hc/en-us/articles/200170786-Restoring-original-visitor-IPs#C5XWe97z77b3XZV)

[Cloudflare ngx\_http\_realip\_module Article](https://support.cloudflare.com/hc/en-us/articles/200170786-Restoring-original-visitor-IPs#JUxJSMn3Ht5c5yq)

Notes and Good to Know Info
---------------------------

[](#notes-and-good-to-know-info)

Does not detect if the client connects via proxy or vpn. Based on HTTP\_CF\_CONNECTING\_IP and prevents spoofing if Cloudflare is not active. Returns REMOTE\_ADDR if Cloudflare is not active.

> ***Warning:*** For now only IPv4

> ***Warning:*** Not recommended for large production applications for not restoring logging IPs as mentioned above.

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

[](#installation)

Composer (recommended)

```
composer require sinanbekar/cf-restore-visitor-ip

```

Usage
=====

[](#usage)

```
// Shorthand Usage:
$ipAddress = \SinanBekar\Cloudflare\Restore::getIp();
```

Setting IP ranges (if there are no changes no need to use you can use shorthand)

```
$ipRanges = ['173.245.48.0/20','103.21.244.0/22','103.22.200.0/22'...];
$cf = \SinanBekar\Cloudflare\Operations::getInstance();
$cf->setCfIpRanges($ipRanges);

$ipAddress = $cf->getClientIpAddress(); // Or \SinanBekar\Cloudflare\Restore::getIp();
```

Other Methods:

```
\SinanBekar\Cloudflare\Operations::getInstance()->getCfIpRanges(); // @return array

\SinanBekar\Cloudflare\Operations::getInstance()->isCorrectCfHeaders(); // @return bool

\SinanBekar\Cloudflare\Operations::getInstance()->isCloudflare(); // @return bool

\SinanBekar\Cloudflare\Helpers::isIpInRange($ip, $range); // @return bool

// Check function comments for more explanation
```

Contributing
------------

[](#contributing)

Please feel free to contribute.

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

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://www.gravatar.com/avatar/fa1d4e7a18a6fcae618cd00849ee31834329a0c3d1127e4b56f64719b89e603f?d=identicon)[sinanbekar](/maintainers/sinanbekar)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/sinanbekar-cf-restore-visitor-ip/health.svg)

```
[![Health](https://phpackages.com/badges/sinanbekar-cf-restore-visitor-ip/health.svg)](https://phpackages.com/packages/sinanbekar-cf-restore-visitor-ip)
```

PHPackages © 2026

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