Copy and paste the above code and save it on your webserver as CaptchaSecurityImages.php. You will also need to place a copy of the "Monofont" font in the same directory as the CaptchaSecurityImages.php file. (Alternatively you can replace the line var $font = 'monofont.ttf'; with the name of whatever font you want to use)

download You can download the captcha zip which contains all the files needed to implement the script including the required font.

Place the following code on your form. This will generate an image with a random string of characters along with the text field where the user will retype the code.

<img src="CaptchaSecurityImages.php" />
Security Code: 
<input id="security_code" name="security_code" type="text" />

You can also specify certain options for the image by passing them as variables to CaptchaSecurityImages.php. The options available are the width and height of the image and the number of characters




<img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" alt="captcha" />
<input id="security_code" name="security_code" type="text" />




Place the following in the code where the form is submitted to. This code will check what the user has typed matches the code in the image.
<?php 
   session_start();
   if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
      // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
      unset($_SESSION['security_code']);
   } else {
      // Insert your code for showing an error message here
   }
?>

