From 12073c0e027d157c271c8964631e742247abebea Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 19 Feb 2017 10:07:42 +0100 Subject: [PATCH] function to get user ip even with reverse proxy --- inc/core.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/inc/core.php b/inc/core.php index ecdcfcc..d4d0d92 100644 --- a/inc/core.php +++ b/inc/core.php @@ -14,14 +14,20 @@ function getUserIP() $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR']; - if(filter_var($client, FILTER_VALIDATE_IP)) - { - $ip = $client; - } - elseif(filter_var($forward, FILTER_VALIDATE_IP)) + + if(strpos($forward,',')) + { + $a = explode(',',$forward); + $forward = trim($a[0]); + } + if(filter_var($forward, FILTER_VALIDATE_IP)) { $ip = $forward; } + elseif(filter_var($client, FILTER_VALIDATE_IP)) + { + $ip = $client; + } else { $ip = $remote;