add new google captcha

This commit is contained in:
Sebastian Korotkiewicz 2014-12-22 21:53:44 +01:00
parent 24323dd63f
commit b6d373573b

View File

@ -697,16 +697,29 @@ class Main extends CI_Controller
function _valid_recaptcha() function _valid_recaptcha()
{ {
if ($this->input->post('recaptcha_response_field')) if ($this->recaptcha_privatekey == null || $this->recaptcha_privatekey == '') {
die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
}
if ($this->input->post('g-recaptcha-response'))
{ {
$pk = $this->recaptcha_privatekey; $pk = $this->recaptcha_privatekey;
$ra = $_SERVER['REMOTE_ADDR']; $ra = $_SERVER['REMOTE_ADDR'];
$cf = $this->input->post('recaptcha_challenge_field'); $rf = trim($this->input->post('g-recaptcha-response'));
$rf = $this->input->post('recaptcha_response_field');
//check $url="https://www.google.com/recaptcha/api/siteverify?secret=".$pk."&response;=".$rf."&remoteip;=".$ra;
$resp = recaptcha_check_answer($pk, $ra, $cf, $rf); $response = $this->curl->simple_get($url);
return $resp->is_valid; $status= json_decode($response, true);
if($status['success'])
{
$recaptcha_response->is_valid = true;
}
else
{
$recaptcha_response->is_valid = false;
}
return $recaptcha_response;
} }
else else
{ {