Queries and SolutionsCategory: CodeIgniterGoogle re-captcha integration in codeignator
bestonetechnologies Staff asked 7 years ago

How to validate google re-captcha in codeignator?

1 Answers
Best Answer
bestonetechnologies Staff answered 7 years 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

14 + 3 =