直接上代码:
function get_real_ip(){ $ip = false; if(!$ip && !empty($_SERVER["HTTP_CLIENT_IP"])){ $ip = $_SERVER["HTTP_CLIENT_IP"]; } if(!$ip && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ipArray = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']); $ip = $ipArray[0]; } if(!$ip && !empty($_SERVER['HTTP_WL_PROXY_CLIENT_IP'])){ $ip = $_SERVER['HTTP_WL_PROXY_CLIENT_IP']; } if(!$ip && !empty($_SERVER['HTTP_X_TRUE_IP'])){ $ip = $_SERVER['HTTP_X_TRUE_IP']; } if(!$ip && !empty($_SERVER['HTTP_X_REAL_IP'])){ $ip = $_SERVER['HTTP_X_REAL_IP']; } if(!$ip && !empty($_SERVER['REMOTE_ADDR'])){ $ip = $_SERVER['REMOTE_ADDR']; } return $ip; }
以上就是这次的全部内容!