首页 > 代码库 > php-ip

php-ip

    function get_client_ip(){
        $headers = array(‘HTTP_X_REAL_FORWARDED_FOR‘, ‘HTTP_X_FORWARDED_FOR‘, ‘HTTP_CLIENT_IP‘, ‘REMOTE_ADDR‘);
        foreach ($headers as $h){
            $ip = $_SERVER[$h];
            // unknown
            if ( isset($ip) && strcasecmp($ip, ‘unknown‘) ){
                break;
            }
        }
        if( $ip ){
            list($ip) = explode(‘, ‘, $ip, 2);
        }
        return $ip;
    }

  

php-ip