by
265 8

Adding Captcha in CodeIgniter

Source: https://www.cloudways.com/blog/captcha-in-codeigniter/
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/3409338/Adding-Captcha-in-CodeIgniter?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
<?php defined('BASEPATH') OR exit('your exit message'); class Captcha extends CI_Controller {    function __construct()    {        parent::__construct();        $this->load->helper('captcha');    }    public function index()    {        if ($this->input->post('submit')) {            $captcha_insert = $this->input->post('captcha');            $contain_sess_captcha = $this->session->userdata('valuecaptchaCode');            if ($captcha_insert === $contain_sess_captcha) {                echo 'Success';            } else {                echo 'Failure';            }        }        $config = array(            'img_url' => base_url() . 'image_for_captcha/',            'img_path' => 'image_for_captcha/',            'img_height' => 45,            'word_length' => 5,            'img_width' => '45',            'font_size' => 10        );        $captcha = create_captcha($config);        $this->session->unset_userdata('valuecaptchaCode');        $this->session->set_userdata('valuecaptchaCode', $captcha['word']);        $data['captchaImg'] = $captcha['image'];        $this->load->view('captcha/index', $data);    }    public function refresh()    {        $config = array(            'img_url' => base_url() . 'image_for_captcha/',            'img_path' => 'image_for_captcha/',            'img_height' => 45,            'word_length' => 5,            'img_width' => '45',            'font_size' => 10        );        $captcha = create_captcha($config);        $this->session->unset_userdata('valuecaptchaCode');        $this->session->set_userdata('valuecaptchaCode', $captcha['word']);        echo $captcha['image'];    } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus