Skip to content

Commit 514f845

Browse files
committed
Accept the action as a variable
1 parent ad20ab6 commit 514f845

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

examples/recaptcha-v3-request-scores.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@
8888
grecaptcha.ready(function() {
8989
document.querySelector('.step1').classList.remove('hidden');
9090
grecaptcha.execute('<?php echo $siteKey; ?>', {action: 'examples/v3scores'}).then(function(token) {
91-
document.querySelector('.token').innerHTML = 'fetch(\'/recaptcha-v3-verify.php?token=\'' + token;
91+
document.querySelector('.token').innerHTML = 'fetch(\'/recaptcha-v3-verify.php?action=examples/v3scores&token=\'' + token;
9292
document.querySelector('.step2').classList.remove('hidden');
9393

94-
fetch('/recaptcha-v3-verify.php?token='+token).then(function(response) {
94+
fetch('/recaptcha-v3-verify.php?action=examples/v3scores&token='+token).then(function(response) {
9595
response.json().then(function(data) {
9696
document.querySelector('.response').innerHTML = JSON.stringify(data, null, 2);
9797
document.querySelector('.step3').classList.remove('hidden');

examples/recaptcha-v3-verify.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
}
4141

4242
// Effectively we're providing an API endpoint here that will accept the token, verify it, and return the action / score to the page
43+
// In production, always sanitize and validate the input you retrieve from the request.
4344
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
4445
$resp = $recaptcha->setExpectedHostname($_SERVER['SERVER_NAME'])
45-
->setExpectedAction('examples/v3scores')
46+
->setExpectedAction($_GET['action'])
4647
->setScoreThreshold(0.5)
4748
->verify($_GET['token'], $_SERVER['REMOTE_ADDR']);
4849
header('Content-type:application/json');

0 commit comments

Comments
 (0)