PHP形式的蜜罐技术

时间:2016-11-06 10:03:09

标签: php wordpress spam honeypot

我尝试在wordpress网站上使用蜜罐技术制作自定义表单。 我的表格看起来像那样。

<form id="form-1" 
    action="<?php echo get_template_directory_uri(); ?>/mail.php" method="post" class="order__form form">
    <p class="form__title">Order and Receive 30% off</p>
    <p class="form__text">fill out this form so you can get sale</p>
    <input type="text" name="name" class="form__item" placeholder="Your name">
    <input type="email" name="email" required class="form__item" placeholder="Email address">
    <p class="robotic" id="pot">
        <label>If you're human leave this blank:</label>
        <input name="robotest" type="text" id="robotest" class="robotest" />
    </p>
    <input type="submit" value="Send" class="button form__button">
</form>

输入名称为robotest的服务器端进行验证。

这是mail.php代码:

<?php
    $mess = '';
    $mess .= '<hr>';
    if($_POST['robotest'] != ''){
        $error = "You are a gutless robot.";
    } else {
        if(isset($_POST['name'])) {
            $name = substr(htmlspecialchars(trim($_POST['name'])), 0, 100);
            $mess .= '<b>Имя отправителя: </b>' . $name . '<br>';
        }
        if(isset($_POST['email'])) {
            if($_POST['email']!=''){
                $email = substr(htmlspecialchars(trim($_POST['email'])), 0, 100);
                $mess .= '<b>E-mail: </b>' . $email . '<br>';
            }
        }
    }

    $mess .= '<b>Заявка пришла со страницы:</b> ' . $_SERVER["HTTP_REFERER"] .'<br>'; 
    $mess .= '<hr>';

    require 'class.phpmailer.php';

    $mail = new PHPMailer();
    $mail->AddAddress('xxx2xxx.com','');
    $mail->IsHTML(true); 
    $mail->CharSet = "UTF-8"; 
    $mail->Subject = "new";
    $mail->From = "new"; 
    $mail->FromName = "new"; 
    $mail->Body = $mess;

    if ($mail->Send()) {
        header('Location: ../'); 
    } else { 
        die ('Mailer Error: ' . $mail->ErrorInfo); 
    }

    header("Location: /thanks/");

?>

当我为robotest添加验证时,此脚本无效。

1 个答案:

答案 0 :(得分:1)

您正在设置$error变量,但您没有在任何地方使用它。

如果您更改:

$error = "You are a gutless robot.";

致:

die( "You are a gutless robot." );

你会得到你想要的东西。