Skip to content

Instantly share code, notes, and snippets.

@nanasess
Created September 12, 2017 09:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanasess/b7898ab5220ba53ace414043632fb11e to your computer and use it in GitHub Desktop.
Save nanasess/b7898ab5220ba53ace414043632fb11e to your computer and use it in GitHub Desktop.
Example for reCAPTCHA V2
<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>
@nanasess
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment