BellaBook3.2: Additional Spam Protection
The 'beauty' of spam bots, if you can think of it that way, is that they don't 'do' JavaScript. Just like a person browsing a webpage with JavaScript disabled, JavaScript just doesn't appear for them. This can be used to our advantage — by using JavaScript to print a field on our page which we then check for and turn people away if we can't find.
Open sign.php and, near the bottom of the file before:
<input type="submit" id="submit" value="Submit" />, add the following:
<script type="text/javascript">
<!--
document.write('<input type="hidden" name="spamtest" id="spamtest" value="SPAMWORD" />');
//-->
</script>
Change SPAMWORD to a word of your choice — a letters and numbers is best. That bit of JavaScript will insert our 'secret' field which won't appear for spambots.
Now, back at the top of the same file, after:
if ((isset($_GET['page'])) && ($_GET['page'] == "process")) {, add this:
if (!isset($_POST['spamtest']) || $_POST['spamtest'] != "SPAMWORD") {
echo "<p>JavaScript must be enabled to comment here due to spam restrictions in place.</p>";
include('footer.php');
exit;
}
Change SPAMWORD to match the word you picked earlier. This must be absolutely identical, otherwise nobody will be able to post messages! Save the file, upload it and that's it — spam bots be gone!
Massive thanks to Bubs who was the inspiration behind this tutorial :)
Tags:
bellabook, javascript,
Last Updated On: 05th May 06 by Jem
Bookmark At: StumbleUpon, Digg

Handy Stuff
Downloads
Friends of 'TT'
Resources