BotDetect CodeIgniter 3.0 CAPTCHA Integration Quickstart

1. Copy CodeIgniter Captcha Library Files

Path Aliases Used Throughout This Guide

  • 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'] = 'botdetect/captcha_handler/index';
Captcha configuration options (application/config/captcha.php):
<?php
// BotDetect PHP Captcha configuration options

$config = array(
  // Captcha configuration for example page
  'ExampleCaptcha' => array(
    'UserInputID' => 'CaptchaCode',
    'ImageWidth' => 250,
    'ImageHeight' => 50,
  ),

);
Load the BotDetect CodeIgniter library and generate the Captcha markup in your Controller:
public function index() // Your controller
{
  // load the BotDetect Captcha library and set its parameter
  $this->load->library('botdetect/BotDetectCaptcha', array(
    'captchaConfig' => 'ExampleCaptcha'
  ));

  // 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 3.0 Captcha integration how to guide.

Other BotDetect PHP CAPTCHA Quickstarts

PHP CAPTCHA Laravel 5.2 CAPTCHA Symfony 3 CAPTCHA
CakePHP 3 CAPTCHA Laravel 5.1 CAPTCHA Symfony2 CAPTCHA
CakePHP 2 CAPTCHA Laravel 5.0 CAPTCHA  
CodeIgniter 2.2 CAPTCHA Laravel 4.2 CAPTCHA  

BotDetect CodeIgniter CAPTCHA System Requirements

CodeIgniter

Supported CodeIgniter Versions:

  • CodeIgniter 3.0.5
  • CodeIgniter 3.0.4
  • CodeIgniter 3.0.3
  • CodeIgniter 3.0.2
  • CodeIgniter 3.0.1
  • CodeIgniter 3.0.0