Create Your Own Php Captcha Challenge Form
What you will need is a customer web form. We may do a tutorial for creating web forms in the near future. So yes, you will need a page with your customer web form on it, and a blank PHP page with absolutely no coding on it whatsoever.
Let’s say the below code is your form. The “action” is to link to the “send.php” page, so the blank PHP page should be called “send.php”, and should also be in the same folder as the page with the form on it! Firstly, on the web form, inside the tags, you will need to create a new input field, we have an example here:
(NOTE: EXCLUDE THE QUOTATION MARKS AROUND THE INSIDE OF THE TAGS!)
<”form”>
<”label”>
<”input type=”text” id=”code” name=”code” /”>
*
<”/label”>
<”input type=”send” value=”Send” type=”submit” /”>
<”/form”>
What we will need to do is write a combination of letters and numbers. We usually use just 4 characters, mainly because of the way our forms are laid out (We can only fit 4 characters) but you can use more. We’d recommend using between 4 and 8 characters so the visitor isn’t put off by having to write an essay of random characters.
Let’s, for example, use the characters “X5KG”.
(NOTE: Unfortunately, the letters are NOT case sensitive)
<”label”>
<”input type=”text” id=”code” name=”code” /”>
* Type X5KG
<”/label”>
As you can see above, we added “Type X5KG” to the label/input. Basically, next to the input box, it says “Type X5KG”.
Next, on our blank PHP page which before, we called “send.php”, we need to write this code down:
(NOTE: EXCLUDE THE QUOTATION MARKS BEFORE “?php” AND AFTER “?”)
<”?php
if (strtolower($ _POST['code']) != ‘x5kg’) {die(‘Wrong code, please try again!’);}
?”>
You may be able to see that after the exclamation mark and equals sign, in single quotes, we wrote the code we came up with eariler, in lowercase, otherwise the whole code won’t work. “!= “x5kg’)”
Where it says “{die(‘Wrong code, please try again!’);}” means the message that comes up if the visitor gets the code wrong. So if they do manage to make a mistake typing in the random characters, it will simply say “Wrong code, please try again!”
OK, that is pretty much it for this mini tutorial. You can check out my website at www.crwd.co.cc, my YouTube channel at www.youtube.com/crwdtutorials, and my other Bukisa content as well.
Thanks for reading.
Written by CRiches
Local small business web design and tutorials from CRiches Web Design, located in Ipswich, UK.
