BotDetect CodeIgniter 3 CAPTCHA Integration Quickstart

Unlike Recaptcha the Stalker -- BotDetect CAPTCHA works in China! Licensable source-code; self-hosted -- doesn't stalk -- nor does it slurp your form-data! Think: GDPR & LGPD!

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/
    libraries/botdetect

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

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

2. Show a Captcha Challenge on the Form

a) If CodeIgniter is a backend for your js-based frontend, perhaps you should start with a guide that describes integration from js-framework point of view: jQuery, Angular, AngularJS, or React.

b) If you are using CodeIgniter forms, here is how to configure Captcha options, and display Captcha in your CodeIgniter 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 CAPTCHA Symfony CAPTCHA
CakePHP CAPTCHA

BotDetect CodeIgniter CAPTCHA System Requirements

CodeIgniter

Supported CodeIgniter Versions:

  • CodeIgniter 3.x