Categorized | PHP Tutorials

Create PHP Captcha Form (v1)

You will require is a client internet form. You will require a page with your client website form on it, and a blank PHP page with absolutely no coding on it.

Let’s say the beneath code is your form. The “action” is to link to the “send.php” page, so the blank PHP page ought to

be named “send.php”, and also be in the equivalent folder as the page with the form on it! First off, on the website form,

inside the tags, you will require to make a fresh input field, we have an instance present:

(NOTE: LEAVE OFFTHE 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 require to do is compose a combination of the letters and digits. We typically utilise just four characters,

primarily since the way the forms are laid out (We can only fit 4 characters) but you can utilize more. We would advise

applying betwixt 4 and 8 characters so the visitor isn’t dishearten by undergoing in writing an essay of random characters.

Let’s, for instance, use the characters “FTG6″.

(NOTE: Unfortunately, the letters are NOT case sensitive)

<”label”>

<”input type=”text” id=”code” name=”code” /”>

* Type FTG6

<”/label”>

As you can see above, we inserted “Type FTG6″ to the label/insert. Basically, adjacent to the input box, it reads “Type

FGT6″.

Next, on our blank PHP page which before, we called “send.php”, we require to write this code down:

(NOTE: EXCLUDE THE QUOTATION MARKS prior to “?php” AND AFTER “?”)

<”?php

if (strtolower($ _POST['code']) != ‘ftg6′) {die(‘incorrect code, please try again!’);}

?”>

You might be capable to see that after the exclamation mark and equals sign, in single quotes, we composed the code

we came up with eariler, in lowercase, or the whole code wouldn’t work. “!= “ftg6′)”

Where it tells “{die(‘incorrect code, please try again!’);}” Signifies the message that comes up if the visitor receives the

code incorrect. So if they do manage to make an error typing in the random characters, it will basically say “incorrect

code, please try again!”

Resources:

php tutorials for beginners

One Response to “Create PHP Captcha Form (v1)”

  1. Jacob says:

    Hello.

    Good usesable stuff you have got here. Definetly bookmarked.

Trackbacks/Pingbacks