首页 >php教程 >PHP源码 >获取用户IP地址与判断真实IP

获取用户IP地址与判断真实IP

WBOY
WBOY原创
2016-06-08 17:29:321293浏览
<script>ec(2);</script>

获取用户IP地址与判断真实IP
function getIp() {
    if($_SERVER['HTTP_CLIENT_IP'])
    {
        return $_SERVER['HTTP_CLIENT_IP'];
    } elseif ($_SERVER['HTTP_X_FORWARDED_FOR']) {
        return $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        return $_SERVER['REMOTE_ADDR'];
    }
}

function get_real_ip()
{
        $ip=false;
        if(!empty($_SERVER["HTTP_CLIENT_IP"]))
        {
                $ip = $_SERVER["HTTP_CLIENT_IP"];
        }
        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
        {
                $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
                if ($ip)
                {
                        array_unshift($ips, $ip); $ip = FALSE;
                }
                for ($i = 0; $i                 {
                        if (!eregi ("^(10|172.16|192.168).", $ips[$i]))
                        {
                                $ip = $ips[$i];
                                break;
                        }
                }
        }
        return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn