Create Simple Captcha on Code Igniter
Posted: May 1st, 2010 | Author: erwin | Filed under: PHP | Tags: Code Igniter, PHP | No Comments »Hello, there.. In this post, I would like to explain how to create simple captcha in Code Igniter. Basic on this captcha is generate random code, save it to session, and check post code with session. If the post code is match then return TRUE and vice versa.
First create validation function on your form controller.
function captcha_check($str)
{
//check captcha
$get_false=FALSE;
if (strtolower(trim($this->session->userdata(“captcha”)))!=strtolower(trim($str)))
{
$get_false = TRUE;
$this->form_validation->set_message(‘captcha_check’, ‘Wrong code, please type again!’.$this->session->userdata(“captcha”));
return FALSE;
}
if ($get_false==FALSE)
{
return TRUE;
}
}




