当我想发送客户端的ip地址和表单时,表单发送的ip地址是: “2a02:a456:4012:X:dcXX:56f5:XXX:555a”它也在不断变化......
而不是我可以使用的实际ip地址,例如禁止使用的人,例如:“85.333.222.111”。
我使用此代码:
function get_client_ip_server() {
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'ONBEKEND';
return $ipaddress;
}
我使用这段代码:
function get_client_ip_env() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'ONBEKEND';
return $ipaddress;
}
返回这些ip地址: “2A02:A456:4012:X:dcXX:56f5:XXX:555A
另外,非常重要:当我拒绝除IP4地址以外的所有内容时,我的.htaccess将不允许我。当我允许我的IP6地址时,它允许我,但该地址会不时变化。
有人可以指出我正确的方向并告诉我这里我做错了什么?非常感谢帮助。
种类问候, 儒略。