step one

The captcha script must be included first thing in the page that contains your form.
<?php
      include('/home/leth/public_html/stuff/captcha/captcha.php');
?>

step two

Adjust your form so that the captcha script processes it instead of your own form handler.

  1. Replace your own form element with this one:
    <form method="post" action="/captcha/captcha.php">
  2. Create a hidden input that contains the path to your own form handler:
    <input type="hidden" name="original_handler" value="/path/to/your/script.php">

step three

Add the captcha image and input box to your form.

<img src="/captcha/image.php" alt="captcha" title="captcha" width="210" height="50" /><br />
Please enter the text you see in the image, including upper and lowercase. <input type="text" name="captcha" />

You may alter the above code to better match the style and layout of your site, as long as the input element name remains unchanged.

step four

Customise the captcha_error.php file to match your own site. You may leave it simply with a message advising that the captcha validation failed, or you might like to put a duplicate of your original form in it to save the user from having to press 'go back'.
If you want to do this, you can save them having to re-enter their information in the form by setting the value attribute in the input fields using the POST data from PHP:

<input type="text" name="your_name" value="<?php echo $_POST['your_name']; ?>" />
captcha
Please enter the text you see in the image, including upper and lowercase.