Posted By


hotdiggity on 07/08/10

Tagged


Statistics


Viewed 565 times
Favorited by 2 user(s)

Invisible Captcha


/ Published in: PHP
Save to your folder(s)

Create a textbox that the bot will presume is just a field it can exploit with rubbish and label it with an indicator to let any viewers without the privileges of CSS know that it is to be left blank.


Copy this code and paste it in your HTML
  1. HTML:
  2. <div class="hidebox">
  3. Please leave blank: <input type="text" id="gotcha" tabindex="-1" name="gotcha" />
  4. </div>
  5.  
  6. PHP:
  7. <?php
  8. if($_POST["gotcha"]!=""){
  9. header("Location: {$_SERVER[HTTP_REFERER]}");exit;
  10. }
  11. ?>
  12.  
  13. CSS:
  14. .hidebox {
  15. position:absolute;
  16. background-color:#CC0000;
  17. left:0px;
  18. top:-500px;
  19. width:1px;
  20. height:1px;
  21. overflow:hidden;
  22. }
  23.  
  24. Note for WordPress:
  25. /wp-content/themes/theme-name/comment.php
  26. add around line 65 (after author,email,url inputs):
  27. <!--Catch sp@m-->
  28. <p class="hidefield"><input type="text" name="gotcha" id="gotcha" size="22" tabindex="-1" />
  29. <label for="gotcha"><small><?php _e('Leave blank!'); ?></small></label>
  30. </p>
  31.  
  32. /wp-comments-post.php
  33. Add after approx. line 54:
  34. $comment_gotcha = ( isset($_POST['gotcha']) ) ? trim($_POST['gotcha']) : null;
  35.  
  36. Add after approx. line 87:
  37. if ( $comment_gotcha != '' ) die( __('Error: Your post has been rejected as spam') );
  38.  
  39. i.e., after
  40.  
  41. if ( '' == $comment_content )
  42. wp_die( __('Error: please type a comment.') );
  43.  
  44. /wp-content/themes/theme-name/style.css
  45. .hidefield { position:absolute; background-color:#CC0000; left:0px; top:-500px; width:1px; height:1px; overflow:hidden; }

URL: http://www.bensky.co.uk/blog/code-tutorials/invisible-capcha-concept-stop-spam-email/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.