您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

获取客户端IP地址

2024/7/1 7:40:33发布211次查看
发现get_client_ip在局域网代理模式下面部分机器无法获取ip,故修改get_client_ip如下解决,但也有可能是我们这边服务器配置的问题:
修改位置:thinkphp\common\funcitons.php->get_client_ip()function get_client_ip($type = 0) {
    $type       =  $type ? 1 : 0;
    static $ip  =   null;
    if ($ip !== null) return $ip[$type];
    if($_server['http_x_real_ip']){//nginx 代理模式下,获取客户端真实ip
        $ip=$_server['http_x_real_ip'];     
    }elseif (isset($_server['http_client_ip'])) {//客户端的ip
        $ip     =   $_server['http_client_ip'];
    }elseif (isset($_server['http_x_forwarded_for'])) {//浏览当前页面的用户计算机的网关
        $arr    =   explode(',', $_server['http_x_forwarded_for']);
        $pos    =   array_search('unknown',$arr);
        if(false !== $pos) unset($arr[$pos]);
        $ip     =   trim($arr[0]);
    }elseif (isset($_server['remote_addr'])) {
        $ip     =   $_server['remote_addr'];//浏览当前页面的用户计算机的ip地址
    }else{
        $ip=$_server['remote_addr'];
    }
    // ip地址合法验证
    $long = sprintf(%u,ip2long($ip));
    $ip   = $long ? array($ip, $long) : array('0.0.0.0', 0);
    return $ip[$type];
}
ad:真正免费,域名+虚机+企业邮箱=0元
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product