获取用户IP地址的三个属性的区别

/ 0评 / 0

1.REMOTE_ADDR:浏览当前页面的用户计算机的ip地址
2.HTTP_X_FORWARDED_FOR: 浏览当前页面的用户计算机的网关
3.HTTP_CLIENT_IP:客户端的ip

public function get_request_ip()
{
if (_SERVER) {
if (isset(
_SERVER['HTTP_X_FORWARDED_FOR'])) {
ip =_SERVER['HTTP_X_FORWARDED_FOR'];
}
else if (isset(_SERVER['HTTP_CLIENT_ip'])) {ip = _SERVER['HTTP_CLIENT_ip'];
}
else {
ip = isset(_SERVER['REMOTE_ADDR']) ?_SERVER['REMOTE_ADDR'] : null;
}
}
else {
if (getenv('HTTP_X_FORWARDED_FOR')) {
ip = getenv( 'HTTP_X_FORWARDED_FOR' );
}
else if (getenv('HTTP_CLIENT_ip')) {
ip = getenv('HTTP_CLIENT_ip');
}
else {
ip = getenv('REMOTE_ADDR');
}
}

returnip;
}