我试图通过循环遍历所有 _POST 数据来防止邮件头注入,但变量没有通过我的验证。我有一些包含斜杠的“日期”字段,其中一些字段可能为空白。不确定这是否与它有关。谁能看出我的逻辑有问题?我不断收到我的“失败”信息。谢谢。
if(isset($_POST['submit'])) {
$boolValidateOK = 1;
function safe( $name ) {
return( str_ireplace(array( "\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:" ), "", $name ) );
}
foreach($_POST as $value){
if(!safe($value)){
$boolValidateOK = 0;
}else{
$boolValidateOK = 1;
}
}
if($boolValidateOK == 1){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$to...etc
$subject...etc
$message...etc
mail($to, $subject, $message, $headers);
$success_message = "win";
}else{
$error_message = "fail";
}
}