From 42c2d8109da4c1724041d82cc05d39b38de0096d Mon Sep 17 00:00:00 2001 From: jcpit Date: Thu, 4 Aug 2022 15:02:13 +1000 Subject: [PATCH] Update functions.php Return IP if running from behind Cloudflare. --- functions.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/functions.php b/functions.php index 12ec0ac5..b328784c 100644 --- a/functions.php +++ b/functions.php @@ -58,16 +58,19 @@ function get_user_agent() { } function get_ip() { + if(defined("CONST_GET_IP_METHOD")){ if(CONST_GET_IP_METHOD == "HTTP_X_FORWARDED_FOR"){ $ip = getenv('HTTP_X_FORWARDED_FOR'); } + else{ - $ip = getenv('REMOTE_ADDR'); + + $ip = $_SERVER["HTTP_CF_CONNECTING_IP"] ?? $_SERVER['REMOTE_ADDR']; } } else{ - $ip = getenv('REMOTE_ADDR'); + $ip = $_SERVER["HTTP_CF_CONNECTING_IP"] ?? $_SERVER['REMOTE_ADDR']; } return $ip;