Baris
Baris

Reputation: 59

reCaptcha Integration: Model or function?

I am working on reCaptcha integration with my project using this tutorial. But what should I do at the fourth step I couldn't understand perfectly and is written below?

Add the following function to your MY_Validation class as seen below in the libraries folder. (If you don’t already have one a MY_Validation class, make one.)

The codes like this under the fourth step on the tutorial.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Validation extends CI_Validation {

function MY_Validation()
{
    parent::CI_Validation();
}

function recaptcha_matches()
{
    $CI =& get_instance();
    $CI->config->load('recaptcha');
    $public_key = $CI->config->item('recaptcha_public_key');
    $private_key = $CI->config->item('recaptcha_private_key');
    $response_field = $CI->input->post('recaptcha_response_field');
    $challenge_field = $CI->input->post('recaptcha_challenge_field');
    $response = recaptcha_check_answer($private_key,
                                       $_SERVER['REMOTE_ADDR'],
                                       $challenge_field,
                                       $response_field);
    if ($response->is_valid)
    {
        return TRUE;
    }
    else 
    {
        $CI->validation->recaptcha_error = $response->error;
        $CI->validation->set_message('recaptcha_matches', 'The %s is incorrect. Please try again.');
        return FALSE;
    }
}

}

Could you help me about the problem? The tutorial link is below.

The tutorial link: https://ellislab.com/forums/viewthread/94299/

Upvotes: 0

Views: 88

Answers (1)

Gopakumar Gopalan
Gopakumar Gopalan

Reputation: 1197

There is much simple library you can use for recaptcha

Download this https://github.com/appleboy/CodeIgniter-reCAPTCHA

(your tutorial link is not working by the way)

Upvotes: 1

Related Questions