Varifikasi Google RECAPTCHA dalam php codeigniter
/**
* VALIDATE RECAPTHCA FUNCTION IS RESPONSIBLE FOR VALIDATING THE REACAPTCHA
*
* @return boolean
*/
function validate_captcha()
{
$recaptcha = trim($this->input->post('g-recaptcha-response'));
$userIp = $this->input->ip_address();
$secret = get_system_settings('recaptcha_secretkey'); //key
$data = array(
'secret' => "$secret",
'response' => "$recaptcha",
'remoteip' => "$userIp"
);
$verify = curl_init();
curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($verify, CURLOPT_POST, true);
curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($verify, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($verify);
$status = json_decode($response, true);
if (empty($status['success'])) {
return FALSE;
} else {
return TRUE;
}
}
Codelone