BotDetect CAPTCHA Crash Course (BotDetect v3.0; deprecated)

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 source file for 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.