Picnic Website Code Tutorials

Simple PHP HoneyPot Tutorial

1/03/2013

View Demo Download source

As usual I've made this dead simple. The honeypot works by, hiding the input from human visitors, but not the spambots. The spambots fill it in just like any other input which tells the PHP or JS Validation that it's spam and prevents the email from sending. Spambot programmers I'm sure are somewhat privy to this by now, so I would call the input something unsuspecting so the bot fills it in and does not become wise to your ways. Placeholder is in place so that if CSS is off the human user knows not to fill it in (so again may want to say something more general here). And autocomplete off is in place so that the human users browser does not by mistake fill in the hidden input.

The PHP

<?php
   // HoneyPot PHP
   if($_POST['honeypot'] != ''){
   die("You spammer!");
   }
   // Just to test PHP
   mail('your@email.com', 'test', 'email');
?>
		

The CSS

#honeypot {
display:none;
}
		

The HTML

<input type="text" id="honeypot" name="honeypot" placeholder="Leave Blank If Human" autocomplete="off">
		

Sponsors

Top Donators

Friends of Mine