Posted By

deanhouseholder on 03/12/14


Tagged

form php filter bots spam block trap webform spiders


Versions (?)

PHP Spam Trap


 / Published in: PHP
 

PHP Spam bot filter

Input a fake form field to catch bots. If they fill out this field, it will automatically be discarded since the form field is invisible on a browser and should never be filled out by a human.

Instructions:

Customize the form below but keep to trick the spam bots/spiders.

This script assumes that the form submits to the same page as the PHP that checks it, but you can easily move it to another page.

  1. <html>
  2. <head>
  3. <title>Spam Bot filter</title>
  4.  
  5. <style>
  6. .form-row {font: 10pt arial;}
  7. h2,legend {font: bold 12pt arial;}
  8. </style>
  9.  
  10. </head>
  11.  
  12. <body>
  13.  
  14. <form method="post">
  15. <!-- Spam Trap Form Field -->
  16. <input name="email" type="text" size="1" style="width: 1px; height: 1px; border: solid 0 #FFF;" /><br clear="all"/>
  17.  
  18. <fieldset>
  19. <legend>Please fill out the following form</legend>
  20. <div class="form-row">
  21. <label for="name">Name:</label>
  22. <input size="30" type="text" name="name" id="name" value="" />
  23. </div>
  24. <div class="form-row">
  25. <label for="email">E-Mail:</label>
  26. <input size="30" type="text" name="email2" id="email" value="" />
  27. </div>
  28. <div class="form-row">
  29. <label for="message">Question:</label>
  30. <textarea name="message" id="message" rows="10" cols="29"></textarea>
  31. </div><br clear="all">
  32. <input type="hidden" name="submit" value="1" />
  33. <input type="submit" value="Send now" class="submit"/>
  34. </fieldset>
  35. </form>
  36.  
  37. <?php
  38. /* HTML EMAIL FORM */
  39. /* Spam bot filter
  40.  * Input a fake form field to catch bots. If they fill out this field, it will automatically
  41.  * be discarded since it is invisible on a browser and should never be filled out by a human.
  42. */
  43.  
  44. $Email = isset($_POST['email2']) ? $_POST['email2'] : '';
  45. $Email_fake = isset($_POST['email']) ? $_POST['email'] : '';
  46. $Name = isset($_POST['name']) ? $_POST['name'] : '';
  47. $Message = isset($_POST['message']) ? $_POST['message'] : '';
  48. $SendTo = '[email protected]';
  49.  
  50. /* Spam bot filter */
  51. if ($_POST){
  52. if($Email_fake == ""){
  53. // Legitimate email
  54. mail($SendTo,'[Spam-free email]','Sent: '.date('m/d/Y h:i:s')."\nSender: $Name ($Email)\nQuestion: $Message", "From: [email protected]
  55. ");
  56. }else{
  57. // Spam Email
  58. mail($SendTo,'[Spam email caught]','Sent: '.date('m/d/Y h:i:s')."\nSender: $Name ($Email)\nFalse Email: $Email_fake\nQuestion: $Message", "From: [email protected]
  59. ");
  60. }
  61. print '<h2>Thank you for your submission.</h2></p>';
  62. }
  63. // End of Spam Filter
  64. ?>

Report this snippet  

You need to login to post a comment.