BotDetect CodeIgniter 3.0 CAPTCHA Integration Quickstart (BotDetect v3.0; deprecated)

1. Copy CodeIgniter Captcha Library Files

Path Aliases Used Throughout This Guide

  • <MYCIAPP>: location of your working CodeIgniter application directory
  • <BDCIPACK>: the downloaded and extracted contents of the BotDetect Captcha CodeIgniter Package
  • Download the BotDetect Captcha CodeIgniter integration package and copy <BDCIPACK>/plugin/codeigniter-3.0/
    libraries/botdetect

    to:
    <MYCIAPP>/application/libraries/botdetect
  • Copy:
    <BDCIPACK>/plugin/codeigniter-3.0/
    controllers/botdetect

    to:
    <MYCIAPP>/application/controllers/botdetect
  • Copy BotDetect PHP Captcha library from:
    <BDCAKEPACK>/lib
    to:
    <MYCIAPP>/application/libraries/botdetect/lib

2. Show a Captcha Challenge on the Form

Register default route of the Captcha library:
$route['botdetect/captcha_handler/index'] = 'botdetect/captcha_handler/index';
$route['botdetect/captcha_resource/get/(:any)'] = 'botdetect/captcha_resource/get/$1';
Load the BotDetect CodeIgniter library and generate the Captcha markup in your Controller:
public function index() { // Your controller

  $captchaConfig = array(  // Captcha parameters:
    'CaptchaId' => 'ExampleCaptcha', // a unique Id for the Captcha instance
    'UserInputId' => 'CaptchaCode' // Id of the Captcha code input textbox
  );
  // load the BotDetect Captcha library
  $this->load->library('botdetect/BotDetectCaptcha', $captchaConfig);
  
  // make Captcha Html accessible to View code
  $data['captchaHtml'] = $this->botdetectcaptcha->Html();
Show the Captcha challenge in the View:
  <link type="text/css" rel="Stylesheet" 
    href="<?php echo CaptchaUrls::LayoutStylesheetUrl() ?>" />
</head>
 
 […]
 
  <?php echo $captchaHtml; ?>
  <input type="text" name="CaptchaCode" id="CaptchaCode" value="" />

3. Check User Input During Form Submission

When the form is submitted, the Captcha validation result must be checked in Controller code:
if ($_POST) {
  // validate the user-entered Captcha code when the form is submitted
  $code = $this->input->post('CaptchaCode');
  $isHuman = $this->botdetectcaptcha->Validate($code);

  if (!$isHuman) {
    // TODO: Captcha validation failed, show error message
  } else {
    // TODO: Captcha validation passed, perform protected action
  }

In-Depth CodeIgniter CAPTCHA Instructions and Explanations

Detailed CodeIgniter Captcha instructions and explanations can be found in the CodeIgniter Captcha integration how to guide.

Other BotDetect PHP CAPTCHA Quickstarts

PHP CAPTCHA Laravel 5.1 CAPTCHA CodeIgniter 2.2 CAPTCHA
CakePHP 3.0 CAPTCHA Laravel 5.0 CAPTCHA  
CakePHP 2.6 CAPTCHA Laravel 4.2 CAPTCHA  

Please Note

The information on this page is out of date and applies to a deprecated version of BotDetect™ CAPTCHA (v3.0).

An up-to-date equivalent page for the latest BotDetect Captcha release (v4) is BotDetect v4 Captcha documentation index.

General information about the major improvements in the current BotDetect release can be found at the What's New in BotDetect v4.0 page.