Quickstart Guide


Securimage is ready to go out of the box with no configuration required. The CAPTCHA image will use the default settings as configured inside securimage.php.

Integrating the code into your existing form is quite simple. First we will start by modifying your current form to include the CAPTCHA image and a text input for code entry.

  1. In the desired position on your form, add the following code to display the CAPTCHA image:
    <img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" />
  2. Next, add the following HTML code to create a text input box:
    <input type="text" name="captcha_code" size="10" maxlength="6" />
    Note: You can change the maxlength and size properties to match your image settings.
  3. The next step is optional, but can be useful to your users if they cannot read the code they are given.
  4. The following code can be used to dynamically reload the CAPTCHA image without having to reload the page. Add this in a convenient location near the CAPTCHA image.
    <a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a>
Now that your form is looking the way it should, we will move onto editing the PHP code that validates the CAPTCHA.

  1. Open the PHP file that processes the form data after submission.
    You can find this by looking at the action value inside your <form> tag.
    Note: In order to use Securimage, your form processor must be written in PHP.
  2. On line 1 of the file, add the following code:
    <?php session_start(); ?>
    It is important to put this at the top of the file before any HTML output.
  3. The next few steps will vary depending on how form validation is handled in your code.
  4. To check if the code is correct, we will make a call to the Securimage class. The following php code should be integrated into the script that processes your form near any error checking that takes place. It should be between <?php ?> tags.
    include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
    $securimage = new Securimage();
    This includes the file that contains the Securimage code and creates a new Securimage object.
  5. Next we will actually check to see if the code was correct.
    if ($securimage->check($_POST['captcha_code']) == false) {
      // the code was incorrect
      // handle the error accordingly with your other error checking
    
      // or you can do something really basic like this
      die('The code you entered was incorrect.  Go back and try again.');
    }
          
    The call to the check method checks the generated CAPTCHA code to the code entered by the user. If the code was incorrect, we use die to stop the script from executing and preventing the form from being submitted. The user must go back and try again.

That is all it takes to get Securimage working. If you run into any problems, check out the F.A.Q. page, or read through the questions and responses below. If you are still running into trouble and can’t get it working, we offer professional installation of Securimage.

  1. 13 Responses to "Quickstart Guide"

  2. There’s a typo on your Quickstart page, which people (like me) may be inadvertently copying into their forms:

    Reload Image

    Should remove _/ before >Reload Image.

    Thanks good catch I think I must have thought I was in an image tag - too much coding!

    By Sean Vickery on Feb 20, 2008

  3. Thanks for your website and a great program. It took me about five hours to get it to work.

    The instructions should be enhanced for the dense people like me who don’t pick up on the subtleties of programing.

    Part was my fault, however it could be made clearer, for the dense people that the above code in the quickstart goes into two seperate files. I know you said that, but it is 2:40 a.m. and it is all a blur.

    Secondly the typo above where you mix the string variable capcha_code and captcha_code has led me around and around.

    But that is the beauty of the internet, we can all learn from each others mistakes. Thanks again.

    Iyel

    By iyel on Feb 28, 2008

  4. A most excellent peice of work.

    Took 5 minutes to plug it all in, and saves me writing my own ..

    The examples above all worked as is ..

    Darrin

    By Darrin Khan on Mar 15, 2008

  5. I finally got it to work after a few hours. Thank you for a really neat addition to my web form. I had to activate the php_gd2 in my php.ini to get the image to appear. That took most of the time. I had no idea about this library being required. I am on an XP box running the latest PHP, MySQL and IIS for my web development.

    Thanks again,

    Bruce

    By Bruce on Mar 23, 2008

  6. Hi - This has worked great for me. I have got most of it to work. However I am having problems with the audio part. When I click on it tries to open it and then says file cannot be opened. Any ideas?

    For the audio, you need to download the sound files separately (a pack is available on the download page). If you did download them, make sure the $audio_path in securimage.php points to the proper directory.

    By Steve on Mar 29, 2008

  7. Very good for help. Great and simply work. Thank a lot.
    David

    By David Khain on Apr 10, 2008

  8. Guys! You’re perfect! Thank you!

    By alx on Apr 14, 2008

  9. Excellent script. Took 5 minutes to install and works like a charm. Thanks

    By Mark on Aug 4, 2008

  10. Took about 10 minutes, excellent instructions!

    By Thomas Mon on Aug 14, 2008

  11. Why the check() method can’t be called twice? I see $_SESSION['securimage_code_value'] = ”; when check is true.

    The primary reason for this is to prevent exploitation of being able to re-submit forms using an old code. If you need to remove it to customize your application, make sure there are checks in place to stop someone from using the same code over and over.

    By Spout on Aug 17, 2008

  12. really good tool, easy to implement. Great guide - thanks!

    By neil on Aug 20, 2008

  13. This is great! Thank you so much!

    By Rory Donohue on Aug 21, 2008

  14. Hi, create script. Im abit of a novice with this, but was wondering if some could help me with the code for a redirect to a thanks.html page once the form is processed?

    Thanks inadvance

    Lee

    To redirect someone using PHP you can use this code:

    header(’Location: http://yoursite.com/thanks.html‘);
    exit;

    Make sure that NOTHING has been output to the browser before calling this, not even any blank spaces or lines; it will not work if there has been output.

    By Dorgs on Aug 24, 2008

Post a Question