本文主要介绍PHP如何获取用户的IP。
方法一
$ip = $_SERVER["REMOTE_ADDR"];
方法二
function GetIP(){ if(!empty($_SERVER["HTTP_CLIENT_IP"])){ $ip = $_SERVER["HTTP_CLIENT_IP"]; }elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; }elseif(!empty($_SERVER["REMOTE_ADDR"])){ $ip = $_SERVER["REMOTE_ADDR"]; }else{ $ip = "无法获取!"; } return $ip; }
方法三
$ip = !empty($_SERVER["HTTP_VIA"]) && !empty($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
目前有 0 条评论