SHARE
TWEET

PHP - Cloudflare IP Address Patch

Mayur_Pipaliya Dec 20th, 2013 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. // Add below PHP code at top of one of common file used.
  4.  
  5. if (isset($_SERVER['HTTP_CF_CONNECTING_IP']))
  6. {
  7.   $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
  8.   $_ENV["REMOTE_ADDR"] = $_SERVER['REMOTE_ADDR'];
  9. }
  10. elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  11. {
  12.   $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_X_FORWARDED_FOR"];
  13.   $_ENV["REMOTE_ADDR"] = $_SERVER['REMOTE_ADDR'];
  14. }
  15. elseif(isset($_SERVER['HTTP_X_REAL_IP']))
  16. {
  17.   $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_X_REAL_IP"];
  18.   $_ENV["REMOTE_ADDR"] = $_SERVER['REMOTE_ADDR'];
  19. }
  20.  
  21.  
  22. ?>
RAW Paste Data
Top