1

How do i get the Real IP of a visitor who is using a proxy if my server is using Cloudflare?

So far this works if a visitor open my server (which is using cloudflare) without using a proxy

isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER["REMOTE_ADDR"];
Jeremy John
  • 1,665
  • 3
  • 18
  • 31
  • As far as I know, you can't. PHP is only capable of reading the IP address purported by the browser. – BenM Jan 23 '13 at 14:17
  • 1
    It dosen't matter what CloudX you are using, if the client's proxy is not transparent you can't get his real IP address, otherwise you can use [this](http://stackoverflow.com/questions/6285775/php-get-the-public-ip) – Mihai Iorga Jan 23 '13 at 14:19
  • http://stackoverflow.com/a/40377635/3599237 – Akam Nov 02 '16 at 10:31

2 Answers2

5

Have you checked HTTP_X_FORWARDED_FOR ?

You can see it in action here: http://canhazip.com/more.php which is passing through CloudFlare. You can use that page if you'd like to test with a proxy as well.

p.s. Disclaimer: I work at CloudFlare.

xxdesmus
  • 1,293
  • 9
  • 16
0

Or you can install mod_cloudflare for Apache.

https://www.cloudflare.com/resources-downloads#mod_cloudflare https://github.com/cloudflare/mod_cloudflare

Diego
  • 215
  • 1
  • 7
  • 14