Finding true IP address using PHP

php-logo

Sometimes a browser may be hiding behind a proxy, – this little function will hopefully get to the root of things:

function userIP(){
// Returns the True IP of the client calling the requested page by first checking to see if HTTP_X_FORWARDED_FOR has a value (proxy)
$userIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
if($userIP == ""){
$userIP = $_SERVER['REMOTE_ADDR'];
}
// Return the IP we've figured out:
return $userIP;
}

Leave a Reply

Your email address will not be published. Required fields are marked *