From 7b0bc12e988588c1b23cc3909512159701bf60bc Mon Sep 17 00:00:00 2001 From: gerandonk Date: Thu, 28 Mar 2024 23:20:14 +0700 Subject: [PATCH] Fix Ip Log for cloudflare tunnel --- init.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/init.php b/init.php index 24dd904..db71de1 100644 --- a/init.php +++ b/init.php @@ -195,7 +195,22 @@ function _log($description, $type = '', $userid = '0') $d->type = $type; $d->description = $description; $d->userid = $userid; - $d->ip = $_SERVER["REMOTE_ADDR"]; + if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) //to check ip is pass from cloudflare tunnel + { + $d->ip = $_SERVER['HTTP_CF_CONNECTING_IP']; + } + elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy + { + $d->ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + elseif (!empty($_SERVER['HTTP_CLIENT_IP'])) //to check ip from share internet + { + $d->ip = $_SERVER['HTTP_CLIENT_IP']; + } + else + { + $d->ip = $_SERVER["REMOTE_ADDR"]; + } $d->save(); }