Zend - The PHP Company




Security

Add Code


Stop robot spamming without loading server  

Type: code fragment
Added by: soapy
Entered: 24/02/2005
Last modified: 03/12/2004
Rating: - (fewer than 3 votes)
Views: 4950
If you want to use this code, please link back to www.officedevils.com - you don't have to, just a comment on your blog will do!

These two code fragments are pretty simple. It randomly generates two numbers, and adds them as hidden variables on your site's submission or sign-up form. The user then has to do the simple sum before the submission is accepted.

Yes, you could write a grep to find the numbers and add them, and submit that, but I am sure that won't happen until a LOT of people start using this, and then you can simply move the variables, or add to it, so that the numbers are turned into words, or change the variable names, or change the sign.

You might also want to make the maths that little bit harder than adding a ten to a digit, to improve the quality of members you get!! ;-)

The big advantage is that this doesn't limit access to those without sight or graphics, such as disabled or WAP users, allowing you to still comply with the regs. on usage.


<?
// Anti-spam code to prevent bots signing up on common PHP based boards
// without the server load of re-writing a gif
// You may need to change some variable names

if ((($number $othernumber) != $sum)) {
echo 
"<font color=red>Please learn basic maths!!</font><br>";
$send "no";

// Add the form data variable names you want to deliberately forget

unset($sender_email);
unset(
$sender_name);
unset(
$sender_phone);
// End variables

}
$number rand(1,10);
$othernumber rand(1,9)*10;
//End anti-spam code
?>


?>
//Anti-spam code in form
$form_block .= "      <input type="hidden" name="number" value="$number"> <tr><td>    
      To prove you are not a bot, please complete the sum $number + $othernumber = 
      <input type="hidden" name="othernumber" value="$othernumber"><input type="text" name="sum" size=3 maxlength=3>";
//End of anti-spam form additions
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories