Build Captcha in CodeIgniter using Captcha Helper

A CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a type of challenge-response test used in computing to determine whether or not the user is human. Captcha code is a combination of some readable text with some distorted shapes to be read only by a human being to confirm that the user is not a bot. In this tutorial, We have shared how to implement Captcha in CodeIgniter using Captcha Helper. This is a very simple example, you can just copy-paste, and change it according to your requirements.
Before started to implement the Build Captcha in CodeIgniter using Captcha Helper, look files structure:
  • codeigniter-send-email-with-attachment
    • application
      • config
        • constants.php
        • routes.php
      • controllers
        • Captcha.php
      • views
        • captcha
          • index.php
        • templates
          • header.php
          • footer.php
    • system
    • index.php
    • assets
      • css
        • style.css
      • uploads
        • captcha_images
Step 1: Load “captcha ” class in controller.
Step 2: Create a controller file
Create a controller file named Captcha.php inside “application/controllers” folder.
  • The controller handles the captcha process.
  • __construct() – Loads the required library and helper.
  • index() – load form and generate Captcha Image.
  • refresh() – refresh Captcha.
Step 3: Create a view
Create a view file named index.php inside “application/views/captcha” folder
Step 7: You can add Javascript code for refresh captcha
Step 4:Create a view(header)
Create a view file named header.php inside “application/views/templates” folder.
This view contains the header section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header section.
Step 5: Create a view(footer)
Create a view file named footer.php inside “application/views/templates” folder.
This view contains the footer section of the webpage.