反垃圾邮件安全问题 php 联系表

anti spam security question php contact form

我有一个工作联系人字段。尽管我使用的是标准的垃圾邮件保护工具,例如蜜罐等。但我几乎每天都会收到垃圾邮件。所以我想我可能会提出一个安全问题。所以我添加了这个:

Spam-question: Which colour has the sky? (lowercase) <input name="spamprotection">

现在我只想在正确回答这个问题的情况下发送表格,否则它应该显示错误消息。但它不再发送但仍显示成功消息。我做错了什么?

我已经将其添加到发送序列中,并且在它正常工作之前:!empty($_POST['spamprotection']) || ($_POST["spamprotection"] = 'blau') ||

// Send the email. 

if (!empty($_POST['spamprotection']) || ($_POST["spamprotection"] = 'blau') ||  mail($to, $subject, $message, $header)) {

    $result = ["color" => "green", "msg" => "Ich habe Ihre Mail erhalten und melde mich in Kürze!"];

    if ($file_type) {

      $result['msg'] .= "";

    }

} else {

    $result = ["color" => "red", "msg" => "Nachricht konnte nicht gesendet werden. Bitte senden Sie mir Ihre Anfrage an bm-translations@email.de"];

}

您的 if 语句中的逻辑无效。

您需要将代码更改为此。

if (isset($_POST['spamprotection']) && $_POST["spamprotection"] == 'blau') {

    $result = ["color" => "green", "msg" => "Ich habe Ihre Mail erhalten und melde mich in Kürze!"];
    mail($to, $subject, $message, $header);

    if ($file_type) {

      $result['msg'] .= "";

    }

} else {

    $result = ["color" => "red", "msg" => "Nachricht konnte nicht gesendet werden. Bitte senden Sie mir Ihre Anfrage an bm-translations@email.de"];

}

说到平等:

$a = '5'; //This sets $a = 5(string);
$b = 5; //This sets $b = 5(int);
$a == $b;  //This checks to see if $a is equal to $b. Will return true.
$a === $b; //This is a strict comparison of $a & $b.  It checks to see if $a is equal to $b as well as the type.  Meaning $a(string) is equal to $b(int). Will return false.