php get the client IP

Customers get the real IP, save to turn the entire database recommendations

 

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)));
    }

 

Guess you like

Origin www.cnblogs.com/6min/p/10945661.html