Online user ip function possible help me please


#1

Hello I have this place on my code I can’t get the user mess address ip in real time, can you help me

function get_ip_address() {
if (!empty(_SERVER['HTTP_X_FORWARDED']) && validate_ip(_SERVER[‘HTTP_X_FORWARDED’]))
return _SERVER['HTTP_X_FORWARDED']; if (!empty(_SERVER[‘HTTP_X_CLUSTER_CLIENT_IP’]) && validate_ip(_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) return _SERVER[‘HTTP_X_CLUSTER_CLIENT_IP’];
if (!empty(_SERVER['HTTP_FORWARDED_FOR']) && validate_ip(_SERVER[‘HTTP_FORWARDED_FOR’]))
return _SERVER['HTTP_FORWARDED_FOR']; if (!empty(_SERVER[‘HTTP_FORWARDED’]) && validate_ip(_SERVER['HTTP_FORWARDED'])) return _SERVER[‘HTTP_FORWARDED’];
return $_SERVER[‘HTTP_CF_CONNECTING_IP’];
}
function validate_ip($ip) {
if (strtolower($ip) === ‘unknown’)
return false;
$ip = ip2long($ip);
if ($ip !== false && $ip !== -1) {
$ip = sprintf(’%u’, $ip);
if ($ip >= 0 && $ip <= 50331647)
return false;
if ($ip >= 167772160 && $ip <= 184549375)
return false;
if ($ip >= 2130706432 && $ip <= 2147483647)
return false;
if ($ip >= 2851995648 && $ip <= 2852061183)
return false;
if ($ip >= 2886729728 && $ip <= 2887778303)
return false;
if ($ip >= 3221225984 && $ip <= 3221226239)
return false;
if ($ip >= 3232235520 && $ip <= 3232301055)
return false;
if ($ip >= 4294967040)
return false;
}
return true;
}


#2

Check out https://support.cloudflare.com/hc/en-us/sections/200805497

If you are using Apache you only need to enable mod_remoteip, configure it, and you should be good to go.


closed #3

This topic was automatically closed after 14 days. New replies are no longer allowed.