【问题标题】:Honeypot technique for php formphp表单的蜜罐技术
【发布时间】:2016-11-06 10:03:08
【问题描述】:

我正在尝试在 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 添加验证时,此脚本不起作用。

【问题讨论】:

  • this script doesn't work 怎么样?空白页?没有信?电脑爆炸了?
  • 它正在工作,但未验证。当机器人填充robotest字段脚本时的主要思想必须是显示错误。但现在每次提交,我都会收到电子邮件。
  • 因为你的逻辑有缺陷。如果你缩进你的代码正确 - 你会看到它。

标签: php wordpress spam honeypot


【解决方案1】:

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

如果你改变:

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

给一个:

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

你会得到你想要的。

【讨论】:

    猜你喜欢
    • 2016-02-14
    • 1970-01-01
    • 2011-04-07
    • 2013-07-29
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 2013-05-27
    相关资源
    最近更新 更多