Location: PHPKode > scripts > Math Guard > readme.html
<h1>MathGuard form antispam protection</h1>

<p>Creating this website I attracted lots of spambots to flood my forum, my programming resources, freelance database and other forms, but you probably know this situation very well.&nbsp; So I decided to create a simple PHP Class which could help me and probably other people to deal with the spam.</p><p>&nbsp;</p><p><img src="http://www.codegravity.com/img/mathguard01.gif" border="1" alt="" /></p><p>&nbsp;</p>

<p>You have probably seen this solution before on some other websites, it&#39;s nothing new, but I did it by myself and the way I wanted and I am using it everywhere it&#39;s needed.</p><p>&nbsp;</p> <h2>The principle of this antispam class&nbsp;</h2> <p>The principle is very simple - The class inserts a small piece of HTML code into your form - an expression consisting of two random numbers, one text input field for user&#39;s answer, and one hidden field with the hashcode.</p><p>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.</p><p>&nbsp;</p><h2> How to set up this PHP antispam class and use it on your website?</h2><h3><strong><u>1. Download the code of MathGuard</u></strong></h3><p>Go to the <a href="http://www.codegravity.com/download/">download section</a> on this website and find there the <strong>mathguard.zip</strong>&nbsp;</p><p>2. Unzip the archive and copy the&nbsp; </p><h3><u><strong>3. Open the code with the form you want to protect</strong></u></h3><p>&nbsp;</p><h3><u><strong>4. Add the following code snippet (the one in the ellipse)</strong></u></h3>  <img src="http://www.codegravity.com/img/mathguard02.gif" border="1" alt="" /><br /><br /><h3><u><strong>5. Protect the form handler</strong></u></h3><p>&nbsp;<img src="http://www.codegravity.com/img/mathguard03.gif" border="1" alt="" /></p>   <pre>		/* first we need to require our MathGuard class */<br />		require (&quot;ClassMathGuard.php&quot;);<br />		/* this condition checks the user input. Don&#39;t change the condition, just the body within the curly braces */<br />		if (MathGuard :: checkResult($_REQUEST[&#39;mathguard_answer&#39;], $_REQUEST[&#39;mathguard_code&#39;])) {<br />			echo (&quot;Great !&quot;);	//insert your code that will be executed when user enters the correct answer<br />		} else {<br />			echo (&quot;Bad answer, go back to school !&quot;);	//insert your code which tells the user he is spamming your website<br />		}<br /></pre><h3><u><strong>6. Open the form in your browser and you should see the mathguard&#39;s security question there</strong></u>&nbsp;</h3><h1>&nbsp;</h1><h3><u><strong>7. Example</strong></u></h3><p><br />&nbsp;There is also an example in the mathguard.zip. It features a simple form and one simple form handler which displays the data.</p><p>&nbsp;</p><h3><u><strong>8. Enjoy !</strong></u>&nbsp;</h3><p>&nbsp;If you&#39;d have any questions, feel free to write to the comments or directly to my email<br /> </p><p>

<a href='http://www.CodeGravity.com'>CodeGravity.com</a>
&nbsp;</p>
								
Return current item: Math Guard