I want to share my PHP code for try help developers. My PHP code is helps to find real user IP address by checking more headers.
function Client_IP(){
# $_SERVER Header List
$headers = array(
'HTTP_CF_CONNECTING_IP', // Cloudflare
/* Proxy Servers - Start */
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_REAL_IP',
'HTTP_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_REAL_IP',
'HTTP_CLUSTER_CLIENT_IP',
'X_FORWARDED_FOR',
'X_PROXYUSER_IP',
'FORWARDED_FOR',
'FORWARDED',
'REAL_IP',
'CLIENT_IP',
'CLUSTER_CLIENT_IP',
'CLIENTIP',
/* Proxy Servers - End */
'REMOTE_ADDR'
);
# Try get IP address with cheacking headers.
foreach ($headers as $index) {
if (isset($_SERVER[$index]) && filter_var($_SERVER[$index], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return $_SERVER[$index];
}
}
# If IP is ::1, accept this ipv6 address as 127.0.0.1.
if ( isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] == "::1" ){
return "127.0.0.1";
}
# Detection failed. Return null.
return null;
}
?>```