Last active
February 9, 2018 06:07
-
-
Save Terkea/ef49f60f8ebe5ca15f0c97c450260e89 to your computer and use it in GitHub Desktop.
reCaptcha v2 check with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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