Search code examples
phpcodeigniterrecaptchacaptcha

can anyone help me to resolve the issue "An Error Was Encountered Non-existent class: recaptchalib"


I am updating recaptcha library to recaptchalib.

I am getting this error.

An Error Was Encountered Non-existent class: recaptchalib

  1. Include the library recaptchalib.php in library folder.
  2. User controller:
    $this->load->library('recaptchalib');

    $data['fincaptcha_ok'] = $this->recaptchalib->recaptcha_get_html();

    $this->recaptchalib->recaptcha_check_answer($_SERVER['REMOTE_ADDR'],$this->input->post('recaptcha_challenge_field'),$this->input->post('recaptcha_response_field'));
    if(!$this->recaptchalib->getIsValid()) {
        $this->load->helper('directory');
        $data['error'] = 'incorrect captcha';
        $data['body_content']           = 'user/register';
        $this->load->view('template', $data);
  1. View:<?php echo $fincaptcha_ok; ?>

Solution

  • Correct me if i'm wrong, but i think you use this recaptcha lib.

    this Library provides a set of functions and has no object implementation. That said it should work if you use it like:

    $this->load->library('recaptchalib');
    
    $data['fincaptcha_ok'] = recaptcha_get_html();
    
    $objResponse = recaptcha_check_answer($_SERVER['REMOTE_ADDR'],$this->input->post('recaptcha_challenge_field'),$this->input->post('recaptcha_response_field'));
    
    if(!$objResponse->is_valid) 
    {
        $this->load->helper('directory');
        $data['error'] = 'incorrect captcha';
        $data['body_content']           = 'user/register';
        $this->load->view('template', $data);
    }
    

    As an additional information, eventually it's better to use the built in captcha helper. Take a closer look at their documenation here.