2005-02-20 – A way to stop link spammers on blogs (code sample)

The code sample below is quite trivial. It is PHP. Just copy and paste into the page which handles the submission validation (probably something like contact.php) and tweak the variable names as you see fit.

// Anti-spam code
if ((($number + $othernumber) != $sum)) {
echo \"<font color=red>Please learn basic
$send = \"no\";
// Add the form data you want to deliberately forget
// Change these sums and ranges as you see fit
$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

Hope this helps! Leave a comment!

Leave a Comment