Created
September 12, 2017 09:16
-
-
Save nanasess/b7898ab5220ba53ace414043632fb11e to your computer and use it in GitHub Desktop.
Example for reCAPTCHA V2
This file contains hidden or 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
<html> | |
<head> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
<script src='https://www.google.com/recaptcha/api.js'></script> | |
<script> | |
function onSubmit(token) { | |
document.getElementById("test").submit(); | |
} | |
</script> | |
<form name="test" action="?" method="post" id="test"> | |
<button | |
class="g-recaptcha" | |
data-sitekey="<sitekey>" | |
data-callback="onSubmit"> | |
Submit | |
</button> | |
</form> | |
<?php | |
//var_dump($_POST); | |
if (isset($_POST['g-recaptcha-response'])) { | |
$data = array( | |
'response' => $_POST['g-recaptcha-response'], | |
'secret' => '<secretkey>' | |
); | |
$curl= curl_init("https://www.google.com/recaptcha/api/siteverify"); | |
curl_setopt($curl,CURLOPT_POST, TRUE); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); | |
curl_setopt($curl,CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($curl,CURLOPT_FOLLOWLOCATION, TRUE); | |
$output = curl_exec($curl); | |
var_dump($output); | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see https://www.google.com/recaptcha/intro/