这是否足以防止标头注入


Is this sufficient to prevent header injection?

在下面我在互联网上找到的代码中,我正在用于我的联系表格,第一部分似乎与安全性有关:

if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
  // detect & prevent header injections
  $test = "/(content-type|bcc:|cc:|to:)/i";
  foreach ( $_POST as $key => $val ) {
    if ( preg_match( $test, $val ) ) {
      exit;
    }
  }

此代码是否足够强大以防止标头注入/安全问题?(我不熟悉PHP)

谢谢

完整代码:

<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
  // detect & prevent header injections
  $test = "/(content-type|bcc:|cc:|to:)/i";
  foreach ( $_POST as $key => $val ) {
    if ( preg_match( $test, $val ) ) {
      exit;
    }
  }
  //send email
 mail( "dfdsfs@ddfdsfd.com", "From page: ".$_POST['name'], $_POST['message']."'nDepuis la page: ". str_replace("http://", "", $_SERVER['HTTP_REFERER']) . "'n" . $_SERVER ['HTTP_USER_AGENT'], "From:" . $_POST['email'] . "'r'n" . "BCC: dfdsfds@dfdfds.com" );
}
?>

注入通常发生在数据库中,就代码而言,它是安全的,但更好的方法是使用 htmlentities(),stripslashes() 函数为此