0

所以我的联系页面看起来像这样

<?php
      include 'header.php';
     foreach($_POST as $key => $value) {
$posts[$key] = filter($value);
                               }

            if(isset($posts['name'])) {
            if($posts['name'] == ""){
            $error = "Please enter your real name!";
            }else if(!isEmail($posts['email'])){
            $error = "Please enter a valid email address!";
            }else if($_POST['message'] == ""){
            $error = "Please enter your message!";
            }else{
            $subject ="Contact";
            $message="{$_POST['message']}";
            $header="From: {$posts['name']} <{$posts['email']}>";
            $to = $site->site_email;
            $send_contact=mail($to,$subject,$message,$header);
            $success = "Message Sent!";
            }
             }
                 ?>
                      <div class="contentbox">
                      <div class="head">Contact</div>

我想以这种方式阻止垃圾邮件发送者......

您每小时只能发送 1 封电子邮件。从这个contact.php页面

请帮助我并将相同的代码发回给我,但使用时间阻塞代码或其他东西进行了编辑。

谢谢

4

2 回答 2

2

存储发送者的IP地址和提交消息的时间。当另一个消息提交时,找到相同的IP地址并比较时间。如果少于一个小时,请给出错误以稍后发送。

于 2012-12-13T03:58:59.920 回答
0
<?php
foreach ($_POST as $key => $value) {
    $posts[$key] = filter($value);
}

if (isset($posts['name'])) {
    if(!empty($_COOKIE["megablocker"])){
        $error = "You can only send one message per hour!";
    }else if ($posts['name'] == "") {
        $error = "Please enter your real name!";
    } else if (!isEmail($posts['email'])) {
        $error = "Please enter a valid email address!";
    } else if ($_POST['message'] == "") {
        $error = "Please enter your message!";
    } else {
        $subject = "Contact";
        $message = "{$_POST['message']}";
        $header = "From: {$posts['name']} <{$posts['email']}>";
        $to = $site -> site_email;
        $send_contact = mail($to, $subject, $message, $header);
        $success = "Message Sent!";
        setcookie("megablocker", 1, strtotime('+1 hour'));
    }
}

include 'header.php';
?>
于 2012-12-13T04:19:19.087 回答