Interview QuestionsCategory: CodeIgniterGoogle re-captcha integration in codeignator
bestonetechnologies Staff asked 4 months ago

How to validate google re-captcha in codeignator?

1 Answers
Best Answer
bestonetechnologies Staff answered 4 months ago

function validate_captcha() {
$captcha = $this->input->post(‘g-recaptcha-response’);
$response = file_get_contents(“https://www.google.com/recaptcha/api/siteverify?secret=you_site_key&response=” . $captcha . “&remoteip=” . $_SERVER[‘REMOTE_ADDR’]);
if ($response . ‘success’ == false) {
return FALSE;
} else {
return TRUE;
}
}

function formSubmit() {
if(isset($_POST)){
$this->form_validation->set_rules(‘g-recaptcha-response’, ‘recaptcha validation’, ‘required|callback_validate_captcha’);
$this->form_validation->set_message(‘validate_captcha’, ‘Please check the the captcha’);
}
}

Your Answer

17 + 5 =