是否可以设置两个不同的标题?

时间:2016-07-09 01:33:38

标签: php security http-headers ip

我获得了这样的用户IP:

// Function to get the client IP address
function get_client_ip() {
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

如果始终设置其中一个标头,我的代码就可以正常工作。否则$_SERVER['HTTP_FORWARDED'] = real IP$_SERVER['HTTP_X_FORWARDED_FOR'] = real ip会发生什么?根据我的条件顺序,$ip将是假ip

所以我想知道其中一个会被设置还是可能有多个?

0 个答案:

没有答案