Created
March 15, 2019 16:43
-
-
Save JhonatanHern/fd336b27fb8a851a1e1f41b21380f507 to your computer and use it in GitHub Desktop.
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
<?php | |
function httpPost($url, $data){ | |
$curl = curl_init($url); | |
curl_setopt($curl, CURLOPT_POST, true); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$response = curl_exec($curl); | |
curl_close($curl); | |
return $response; | |
} | |
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['g-recaptcha-response'])) { | |
// Build POST request: | |
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify'; | |
$recaptcha_secret = 'YOUR_SECRET'; | |
$recaptcha_response = $_POST['g-recaptcha-response']; | |
// Make and decode POST request: | |
$data = array( | |
'secret' => $recaptcha_secret, | |
'response' => $recaptcha_response | |
); | |
$recaptcha = httpPost($recaptcha_url,$data); | |
$recaptcha = json_decode($recaptcha); | |
// Take action based on the score returned: | |
if ($recaptcha->score < 0.5) { | |
header("Location:fail.html?bot=1"); | |
die(); | |
} | |
}else{ | |
echo "bot checking error, token missing"; | |
die(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment