I'm just desperately trying to make it work... Been sitting on this for a good 4 hours
I tried many many solutions from google, I have no idea what to do now so posting here is my last resort.
I also tried using recaptcha v2 which would honestly be a better option but I gave up on it before because nothing worked when I tried to add it for a button.
Here is my code:
index.php
<?php
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Get Key</title>
<link rel="stylesheet" href="style.css">
<script src="index.js"></script>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script src="https://www.google.com/recaptcha/api.js?render=6LexkIoiAAAAAGxENEyPQ-e5sVubBaKlX9HSVM31" async defer></script>
</head>
</head>
<body>
<div class="center">
<form id="getkeyForm" action="captchahandler.php" method="POST">
<h3>Please complete the linkvertises to get the key</h3>
<h3>Linkvertise (1/4)</h3>
<input type="submit" name="submit" onclick="prnt()" id="submitBtn" class="submitBtn" value="Submit">
</form>
</div>
</body>
</html>
captchahandler.php
<?php
define("RECAPTCHA_V3_SECRET_KEY", 'my-secret-key');
$token = $_POST['token'];
$action = $_POST['action'];
// call curl to POST request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('secret' => RECAPTCHA_V3_SECRET_KEY, 'response' => $token)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$arrResponse = json_decode($response, true);
// verify the response
if($arrResponse["success"] == '1' && $arrResponse["action"] == $action && $arrResponse["score"] >= 0.5) {
// valid submission
// go ahead and do necessary stuff
echo 'SUCCESS';
echo $response;
} else {
// spam submission
// show error message
echo 'FAIL';
echo $response;
}
?>
index.js
$('#getkeyForm').submit(function(event) {
event.preventDefault();
grecaptcha.ready(function() {
grecaptcha.execute('6LdLk7EUAAAAAEWHuB2tabMmlxQ2-RRTLPHEGe9Y', {action: 'getkey'}).then(function(token) {
$('#getkeyForm').prepend('<input type="hidden" name="token" value="' + token + '">');
$('#getkeyForm').prepend('<input type="hidden" name="action" value="getkey">');
$('#getkeyForm').unbind('submit').submit();
});;
});
});
var_dump($_POST);
at the top ofcaptchahandler.php
to make sure all of your form inputs are being submitted.