Skip to content

Instantly share code, notes, and snippets.

@Terkea
Last active February 9, 2018 06:07
Show Gist options
  • Save Terkea/ef49f60f8ebe5ca15f0c97c450260e89 to your computer and use it in GitHub Desktop.
Save Terkea/ef49f60f8ebe5ca15f0c97c450260e89 to your computer and use it in GitHub Desktop.
reCaptcha v2 check with PHP
//check if its submited and not empty
if($this->input->post('g-recaptcha-response') && !empty($this->input->post('g-recaptcha-response'))){
//your site secret key
$secret = '6LeI4RcTAAAAAKDCD8gNAxyl2_82Rrn0M6S0UTAV';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$this->input->post('g-recaptcha-response'));
//decode and store the response data
$check = json_decode($verifyResponse);
//check if its passed
if ($check->success == true) {
echo "successfully pass";
}else{
echo "try again";
}
}else{
echo "captcha not submited";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment