Good Form Security - no CAPTCHA

后端 未结 9 1748
情歌与酒
情歌与酒 2020-12-08 06:44

Is there a good method of form security that does not involve CAPTCHA? CAPTCHA is so annoying, but I need security because I am getting form spam. My form is

9条回答
  •  自闭症患者
    2020-12-08 07:22

    If all you are doing is avoiding spam bots (automated programs that seek

    tags, fill in all fields, then submit the form), then a simple solution is to do as Paolo said: use JavaScript to add a hidden field. The disadvantage is for people who disable JavaScript.

    Feel free to use this:

    
      
      



    Then place the following as "contact.php" in the same directory:

    setSubject( $subject )
        ->setFrom( array( $email => $name ) )
        ->setTo( array( 'YourEmailAddress' => 'Your Name' ) )
        ->setPriority( 1 )
        ->setBody( $message )
      ;
    
      if( $mailer->send( $message ) ) {
        header( 'Location: contacted.html' );
        $contacted = true;
      }
    }
    
    if( $contacted === false ) {
      not_contacted();
    }
    ?>
    

    Should prevent 99% of spam.

    I have not added constants, but I'm sure you can figure out where to change the script. I've removed the part where it redirects to different pages depending on what was (or was not) entered by the user (e.g., missing full name, e-mail address, message, and such). If you want a full version of the script, let me know and I'll fix the code to be more new-developer-friendly.

    Note the Swift Mailer dependency.

提交回复
热议问题