BotDetect CAPTCHA Crash Course

On this page we demonstrate how easy it is to integrate BotDetect Captcha in your forms.

We'll use default BotDetect settings; to see how powerful and customizable BotDetect is, check the BotDetect features demo.

1. Copy Captcha Library Files

Copy botdetect.php and the botdetect folder to your website folder. These files are included in the BotDetect download package (the lib sub-folder).

2. Show a Captcha Challenge on the Form

On the very top of the PHP form you want to protect against bots, add:
<?php session_start(); ?>
<?php require("botdetect.php"); ?>
On the PHP form you want to protect against bots, add:>
  <link type="text/css" rel="Stylesheet" 
    href="<?php echo CaptchaUrls::LayoutStylesheetUrl() ?>" />
</head>

  […]

<?php // Adding BotDetect Captcha to the page 
  $SampleCaptcha = new Captcha("SampleCaptcha");
  $SampleCaptcha->UserInputID = "CaptchaCode";
  echo $SampleCaptcha->Html(); 
?>

<input name="CaptchaCode" id="CaptchaCode" type="text" />

3. Check User Input During Form Submission

When the form is submitted, the Captcha validation result must be checked:
<?php 
  if ($_POST) {
    // validate the Captcha to check we're not dealing with a bot
    $isHuman = $SampleCaptcha->Validate();
    
    if (!$isHuman) {
      // TODO: Captcha validation failed, show error message
    } else {
      // TODO: Captcha validation passed, perform protected action
    } 
  }
?>

BotDetect CAPTCHA Options

To find more about configuring BotDetect and integrating it in various usage scenarios, please check the getting started with BotDetect Captcha page.

Please Note

BotDetect 3.0 PHP Captcha Library Beta1 is an in-progress port of BotDetect 3.0 Captcha, and we need you to guide our efforts towards a polished product. Please let us know if you encounter any bugs, implementation issues, or a usage scenario you would like to discuss.

BotDetect 3 PHP is already available for purchase at a 33% discounted pre-release price.