用PHP如何得到访问者的真实IP?

WBOY
Release: 2016-05-19 14:05:27
Original
1219 people have browsed it

在php中,通常我们用$_SERVER['REMOTE_ADDR']得到访问者的ip。但当访问者使用了代理,它只能得到代理的ip。这时使用下面的函数就能得到访问者的真实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;
}

事实上这个函数也不是万能,众所周知,头信息是可以伪造的。O(∩_∩)O

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template