如何制作具有联系时间限制的联系页面

时间:2012-12-13 03:54:06

标签: php javascript html

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

<?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>

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

每小时只能发送一封电子邮件。来自这个contact.php页面

请帮我解决此问题,并将此相同的代码发回给我,但使用时间阻止代码或其他内容进行编辑。

由于

2 个答案:

答案 0 :(得分:2)

存储发件人的IP地址并提交时间消息。提交另一条消息时,找到相同的IP地址并比较时间。如果不到一个小时,请稍后发送错误。

答案 1 :(得分: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';
?>