GithubHelp home page GithubHelp logo

cf-restore-visitor-ip's Introduction

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 ?

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

Cloudflare ngx_http_realip_module Article

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

Composer (recommended)

composer require sinanbekar/cf-restore-visitor-ip

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

Please feel free to contribute.

cf-restore-visitor-ip's People

Contributors

sinanbekar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.