CAPTCHA Helper
CAPTCHA Helper : Codeigniter provides the CAPTCHA Helper which contains the functions that are used to create CAPTCHA images. Here is in this tutorial we are going to explain how you can create CAPTCHA images using the codeiniter’s CAPTCHA. CAPTCHA is used for human verification. Basically it is used to prevent the automated robots, bots, spams to access the website. CAPTCHA is basically image which contains some random string, numbers which needs to be verified by the user.
CAPTCHA Helper in Codeigniter
Let us go step by step to understand how captcha helper works in codeigniter.
Load CAPTCH Helper
You can load CAPTCHA(helper) simply as below –
Load CAPTCHA Helper in Codeigniter:
$this->load->helper('captcha'); |
Now you can user CAPTCHA(helper) functions to create CAPTCHA images.
How to use Codeigniter CAPTCHA Helper ?
If CAPTCHA(Helper) is loaded you can create CAPTHCA simply as below –
Load CAPTCH(Helper) in Codeigniter:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Captcha extends CI_Controller { public function generateCaptcha(){ $this->load->helper('captcha'); $val = array( 'word' => rand(1000, 10000), 'img_path' => './captcha/', 'img_url' => 'http://tutorialsplane.com/runtest/codeigniter/demo/captcha/', 'font_path' => 'arial.ttf', 'img_width' => '200', 'img_height' => 50, 'expiration' => 7200, 'word_length' => 7, 'font_size' => 20, 'img_id' => 'Imageid', 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'colors' => array( 'background' => array(255, 255, 255), 'border' => array(255, 255, 255), 'text' => array(0, 0, 0), 'grid' => array(255, 40, 40) ) // background : White // border: White //Text: black text and red grid ); $captcha = create_captcha($val); echo $captcha['image']; } } ?> |
In the above example we have created a controller and added a method which handles the captcha generation.
If you run the above example it will produce output something like this –
More About CAPTCHA Helper
Let’s have look over more example and demo here.
Advertisements