Most of Web Designer face a issue when they create a new website for their clients. This issue is that the website they have created is automatically sending 100 of forms to the client email address. Even though some fields are made required still clients get 100 of emails.
Solution to this is to add a Captcha to your Website. Most of Website Developer add a image based Captcha. But this Captcha sometimes make it very difficult for the clients to read the text in image based captcha which results in losing of good lead. Text based Captcha can be used but bots can easily read them and fill the form easily.
To solve this we can use calculation based text Captcha. As spam bots cannot do the calculation this method is very useful. Only disadvantage is if complex addition or subtraction is shown than clients may have to spend some time to submit the Captcha.
This Article is going to show you how to add numeric calculation captcha in the website or contact form.
Please Follow The Procedure
Step 1 : If Your Website Is in Php then this code will work perfectly and for HTML website just SAVE your contact page(HTML) or the page where you want to add captcha in .PHP form.
Step 2 : On the very first line above the <!DOCTYPE html PUBLIC “—-”> Code just Paste this code
$digit1 = mt_rand(1,20);
$digit2 = mt_rand(1,20);
$math = “$digit1 + $digit2″;
$_SESSION['answer'] = $digit1 + $digit2;
This Code Will Generate 2 Random Numbers And Do The Calculation Of Them.
Step 3 : Add The Following Code Where You Want To Display Captcha.
(If You want to add captcha in the contact form so put the code on above the save button’s code
(Like : <input type=”submit” name=”submit” />) // this is save button code.)
<input type=”hidden” value=”<?php echo $_SESSION['answer'] ?>” name=”hdn” />
What’s <?php echo $math; ?> = <input name=”answer” type=”text” />
Here value=”<?php echo $_SESSION['answer'] ?>” is the answer Which is pass to the hidden field.
And <?php echo $math; ?> is the random value generated by the function.
(Like :<form action=”contact_email.php” id=”" method=”post” name=”contact” enctype=”multipart/form-data” onSubmit=”return validate();”>)
Here Validate is The Name Of Function.
if (x==null || x==”")
alert(“Please Enter Security Code.”);
alert(“Error! The Codes Do Not Match”);
// Code to send Email
Display Failure page.
To understand it more properly You Can watch the video