修复获取用户IP导致的报错问题
This commit is contained in:
@@ -166,19 +166,17 @@ function tips($message, $url = 'javascript:history.go(-1);')
|
||||
*/
|
||||
function get_real_ip()
|
||||
{
|
||||
$ip = false;
|
||||
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
|
||||
$ip=FALSE;
|
||||
//客户端IP 或 NONE
|
||||
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
|
||||
$ip = $_SERVER["HTTP_CLIENT_IP"];
|
||||
}
|
||||
//多重代理服务器下的客户端真实IP地址(可能伪造),如果没有使用代理,此字段为空
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$ips = explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
if ($ip) {
|
||||
array_unshift($ips, $ip);
|
||||
$ip = FALSE;
|
||||
}
|
||||
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
|
||||
for ($i = 0; $i < count($ips); $i++) {
|
||||
$istart = substr($str , 0 , 3);
|
||||
if ($istart != "10." && $istart != "172" && $istart != "16." && $istart != "192" && $istart != "168"){
|
||||
if (!preg_match ("/^(10│172.16│192.168)./", $ips[$i])) {
|
||||
$ip = $ips[$i];
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user