获取访问者的 客户端IP地址
程序员文章站
2022-05-06 16:38:08
...
/** * 获取访问者的 客户端的ip地址
if ($_SERVER['HTTP_X_FORWARDED_FOR']){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif ($_SERVER['HTTP_CLIENT_IP']){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif ($_SERVER['REMOTE_ADDR']){
$ip = $_SERVER['REMOTE_ADDR'];
}elseif (getenv('HTTP_X_FORWARDED_FOR')){
$ip = getenv('HTTP_X_FORWARDED_FOR');
}elseif (getenv('HTTP_CLIENT_IP')){
$ip = getenv('HTTP_CLIENT_IP');
}elseif (getenv('REMOTE_ADDR')){
$ip = getenv('REMOTE_ADDR');
}else{
$ip = '';
}
return $ip;
}
*/
echo $ip = getIP();
function getIP() {if ($_SERVER['HTTP_X_FORWARDED_FOR']){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif ($_SERVER['HTTP_CLIENT_IP']){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif ($_SERVER['REMOTE_ADDR']){
$ip = $_SERVER['REMOTE_ADDR'];
}elseif (getenv('HTTP_X_FORWARDED_FOR')){
$ip = getenv('HTTP_X_FORWARDED_FOR');
}elseif (getenv('HTTP_CLIENT_IP')){
$ip = getenv('HTTP_CLIENT_IP');
}elseif (getenv('REMOTE_ADDR')){
$ip = getenv('REMOTE_ADDR');
}else{
$ip = '';
}
return $ip;
}
以上就介绍了获取访问者的 客户端IP地址,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。