MathGuard is free PHP class that everyone can use as anti-spam protection for the website forms. It's also a suitable solution when there is no PHP GD support from the webhosting company.
featuring more complex Anti-spam security question rendering - these numbers consist of the random letters
You have probably seen this solution before on some other websites, it's nothing new, but I did it by myself and the way I wanted and I am using this anti-spam everywhere it's needed. The good thing is, that it works.
The principle of this PHP anti-spam class is very simple - The class inserts a small piece of HTML code into your PHP form - an expression consisting of two random numbers, one text input field for user's answer, and one hidden field with the hashcode.
When user submits the form with the answer, the answer is being hashed and compared to the security code that has been submitted as well.
Go to the download section on this website and find there mathguard-v0.2.zip
Unzip the archive and copy the file ClassMathGuard.php into the folder with forms and action handlers you want to use.
Open the code with the PHP or HTML form you want to protect
Add the following PHP code snippet (the one in the ellipse)
Protect the form handler
/* first we need to require our MathGuard class */
require ("ClassMathGuard.php");
/* this condition checks the user input. Don't change the condition,
just the body within the curly braces */
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'],
$_REQUEST['mathguard_code'])) {
echo ("Great !");
//insert your code that will be executed when user enters the correct answer
} else {
echo ("Bad answer, go back to school !");
//insert your code which tells the user he is spamming your website
}
There is also an example in the downloaded archive. It features a simple form and one simple form handler which displays the data. I recommend you also to watch the flash demo on this website that shows a real example how to integrate mathguard.