Today, We want to share with you captcha in codeigniter.In this post we will show you recaptcha in codeigniter 4, hear for how to add google captcha in codeigniter? we will give you demo and example for implement.In this post, we will learn about Codeigniter Form Validation with Google reCAPTCHA with an example.
Example – Captcha In CodeIgniter Using Captcha Helper
CodeIgniter CAPTCHA Helper helps to generate recaptcha image with customization options.
- Make and display recaptcha image.
- Get user input and submit for comparison.
- Compare user input with recaptcha word and return the status.
create captcha in CodeIgniter.
// Captcha configuration $config = array( 'img_path' => 'all_available_pictures/', 'img_url' => base_url().'all_available_pictures/', 'img_width' => '150', 'img_height' => 50, 'word_length' => 8, 'font_size' => 16 ); $datainfo = create_captcha($config);
'font_path' => './path/to/fonts/texb.ttf'
Controller (onlineSecurity.php)
load->helper('datainfo'); } public function index(){ if($this->input->post('submit')){ $inputonlineSecurity = $this->input->post('datainfo'); $sessonlineSecurity = $this->session->userdata('datainfoCode'); if($inputonlineSecurity === $sessonlineSecurity){ echo 'onlineSecurity code matched.'; }else{ echo 'onlineSecurity code was not match, please try again.'; } } $config = array( 'img_path' => 'all_available_pictures/', 'img_url' => base_url().'all_available_pictures/', 'img_width' => '150', 'img_height' => 50, 'word_length' => 8, 'font_size' => 16 ); $datainfo = create_captcha($config); $this->session->unset_userdata('datainfoCode'); $this->session->set_userdata('datainfoCode',$datainfo['word']); $data['datainfoImg'] = $datainfo['image']; $this->load->view('datainfo/index', $data); } public function refresh(){ $config = array( 'img_path' => 'all_available_pictures/', 'img_url' => base_url().'all_available_pictures/', 'img_width' => '150', 'img_height' => 50, 'word_length' => 8, 'font_size' => 16 ); $datainfo = create_captcha($config); $this->session->unset_userdata('datainfoCode'); $this->session->set_userdata('datainfoCode',$datainfo['word']); echo $datainfo['image']; } }
View (datainfo/index.php)
Captcha implement in CodeIgniter by www.pakainfo.com Submit the word you see below:
I hope you get an idea about Validate recaptcha ajax and codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.