Simple Captcha Script


Support for this script is available here.

I wrote this Simple Captcha Script because I couldn't find a simple and small one that I could use without needing to include a giant_captcha.inc file!
If you use the code, please consider linking back to me - otherwise, my only request if that you keep the GPL License (General Public License) on top of the script.

Now you can download it here and use it in your forms very easily.

  • First, download the package and decompress the files (the size of the package is big because it contains font files), then upload it on your website.
  • Run the system_check.php to check if the script is compatible with your PHP configuration (if not, it will tell you why).
  • If everything is fine, you will get a message letting you know.

If you don't know how to use a captcha image in your forms, don't worry, here are some instructions to get you started:
  • Place it into your form like this:
    <img src="http://www.your-websites-url.com/captcha/captcha.php" />
    At this point, the captcha image will show up wherever you put it into your page, and the secret code is written into a session variable ($_SESSION['CAPTCHA']).

    Here is how it will look:

    Captcha Script Sample
    You can refresh this page and note the changes.


  • Place a form field in front of your captcha image, and ask the user to 'Do the math' like this:
    <input type="text" name="CAPTCHA" />


  • Place this line of code on the very top of your submit form:

    <?php
    session_start
    ();
    ?>


  • When the user submits the form, check the user input against the $_SESSION['CAPTCHA'], like this:

    <?php
    if( $_SESSION['CAPTCHA'] != strip_tags($_POST['CAPTCHA']) ) {
        echo 
    'You entered the wrong code!';
        
    // give him an option to go back and fix it!
    } else {
        
    // He is not a robot so process your form here
    }
    ?>
Note: in order for this script to work, your users have to have their cookies on, I will make another version that is independent of cookies.

Download the package.
If you have any questions, suggestions or problems, visit our support forums.


What is a Captcha Image?

Captcha is an image with random characters in it, the purpose of captcha images is to prevent your forms from being submitted to by an autosubmit script.

You can use captcha images to make your own forms secure and prevent annoying automatic submissons of links etc., it's really simple.