Update functions.php

Return IP if running from behind Cloudflare.
This commit is contained in:
jcpit 2022-08-04 15:02:13 +10:00 committed by GitHub
parent c1ff2011a4
commit 42c2d8109d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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;