Created
January 18, 2018 10:21
-
-
Save azazqadir/6dfe8cd2306d22ef377b1dee98baace5 to your computer and use it in GitHub Desktop.
Adding Captcha in Forms in CodeIgniter Website: https://www.cloudways.com/blog/captcha-in-codeigniter/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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']; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment