有时IPv4地址而不是IPv6地址

分享于 

1分钟阅读

互联网

  繁體

问题:

为此,我使用下面的代码shippet获取用户的IP地址:


if (isset($_SERVER['HTTP_CLIENT_IP'])){


 $ip = $_SERVER['HTTP_CLIENT_IP'];


}else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){


 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];


}else if(isset($_SERVER['HTTP_X_FORWARDED'])){


 $ip = $_SERVER['HTTP_X_FORWARDED'];


}else if(isset($_SERVER['HTTP_FORWARDED_FOR'])){


 $ip = $_SERVER['HTTP_FORWARDED_FOR'];


}else if(isset($_SERVER['HTTP_FORWARDED'])){


 $ip = $_SERVER['HTTP_FORWARDED'];


}else if(isset($_SERVER['REMOTE_ADDR'])){


 $ip = $_SERVER['REMOTE_ADDR'];


}else{


 echo "ERROR";


}



这一切都很好,但有时我得到一个IPv4地址,我还可以使用ping -6 server_ip ping服务器,


答案1:

没有什么错误,它可以通过IPv4连接。



添加  SOM  IPV6  IPV4  
相关文章