

Now, we need to get the data from the captcha into the PHP for it to process.

Now open that file (create it if there is none), and we’ll begin the validation process. You can name the file in the action attribute whatever you want, but it MUST end in. In the line of code containing the beginning of your form, you should have at least the method and action attributes already specified. This data will be checked against the user/robot’s input. Lines 4-6 hold the math captcha data that will be sent once the user clicks the submit button. Line 2, in essence, displays the math problem in a way that the user can understand it. You should add this part to the end of your form, right before the Submit button.

You can put this code at the beginning of your form.įor the HTML part, all we need is a label, input field, and three hidden fields to store our two numbers and the integer representing our operand. We can display to the user a plus, minus, or multiplication sign on their end. Now how about the operand? The solution is to choose a random number between 0 and 2, and have each number represent a different operand. the rand(int $min, int $max) function can provide us with random integers. In PHP, making random numbers is simple enough. I left out division because of the possibility of requiring decimals (e.g.

Our captcha will be math based, so it will ask a random math question such as “What is 3+2?” or “What is 8 * 4?”. All we need to do then, is add on a captcha system to the form. So far, we already have an HTML form, which submits data to another PHP page for processing.
