it was a plugin for captcha in Codigniter. Now its very with new version to embed captcha in codeigniter. Captcha helper is available in new codeigniter version
Controller
class Parents extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('parent_model');
$this->load->helper('captcha');
}
function signup() {
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . 'captcha/'
);
$cap = create_captcha($vals);
$details['image'] = $cap['image'];
$details['imgName'] = $cap['time'];
$details['captchaId'] = $this->parent_model->createCaptcha($cap);
$this->load->view('signup', $details);
}
function checkCaptcha($captcha, $captchaId) {
$accuracy = $this->parent_model->checkCaptchaAccuracy($captcha, $captchaId);
if ($accuracy > 0) {
echo '1';
} else {
echo '0';
}
}
}
Model
class Parent_Model extends CI_Model {
function __construct() {
parent::__construct();
}
function createCaptcha($cap) {
$data = array(
'captcha_time' => $cap['time'],
'ip_address' => $this->input->ip_address(),
'word' => $cap['word']
);
$query = $this->db->insert_string('captcha', $data);
$this->db->query($query);
return $captchaId = $this->db->insert_id();
}
function checkCaptchaAccuracy($captcha, $captchaId) {
$this->db->from("captcha");
$this->db->where('word', $captcha);
$this->db->where('captcha_id', $captchaId);
$this->db->where('ip_address', $this->input->ip_address());
$availabilty = $this->db->get();
return $numRows = $availabilty->num_rows();
}
}
View
Javascript
function checkCaptcha(baseurl,captcha,captchaId){
document.getElementById('captchaId').value = captchaId;
httpObject = getHTTPObject();
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(xmlhttp.responseText==1){
document.getElementById('message').innerHTML = 'Entered Captcha is Correct';
}
}
}
xmlhttp.open("POST", baseurl+"/user/checkCaptcha/"+captcha+'/'+captchaId, true);
xmlhttp.send(null);
}
Post a Comment
Post a Comment