php获取客户IP

获取客户真实IP,保存到数据库建议转整

 

function getIp(){
        $ip = '';
        if(!empty($_SERVER['HTTP_CLIENT_IP'])){
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        }else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }else if(!empty($_SERVER['REMOTE_ADDR'])){
            $ip = $_SERVER['REMOTE_ADDR'];
        }else{
            $ip = '';
        }
        return bindec(decbin(ip2long($ip)));
    }

 

posted @ 2019-05-29 19:10  1553  阅读(117)  评论(0编辑  收藏  举报