In php, we usually use $_SERVER['REMOTE_ADDR'] to get the visitor's IP. But when the visitor uses a proxy, it can only get the proxy's IP. At this time, you can use the following function to get the visitor's real IP:
function getRealIpAddr(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])){//check ip from share internet
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){//to check ip is pass from proxy
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
In fact, this function is not omnipotent. As we all know, header information can be forged. O(∩_∩)O