Require a captcha for visitor submissions and for login.

Without the form field, the check was skipped. A solved captcha lasts
30 minutes in the session.
This commit is contained in:
tim
2026-09-25 21:54:14 +02:00
parent 1698680e24
commit 1468cf7138
8 changed files with 97 additions and 25 deletions
-19
View File
@@ -2,25 +2,6 @@
$result = get_post_data(TRUE);
extract($result[0], EXTR_OVERWRITE);
if (isset($_POST['g-recaptcha-response'])) {
$captcha = $_POST['g-recaptcha-response'];
if (! $captcha) {
$validate['captcha'] = 'Invalid captcha. Please try again.';
include('./write.inc.php');
return;
}
$captcha_resp = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".urlencode(config('RECAPTCHA_SECRET'))."&response=".
$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
var_dump($captcha_resp);
// PHP 8 treats the bare word "success" as an undefined constant, so decode the JSON reply
$captcha_json = json_decode((string)$captcha_resp);
if (empty($captcha_json->success)) {
$validate['captcha'] = 'The words you typed in the captcha were not correct. Please try again.';
include('./write.inc.php');
return;
}
}
echo '<p>Please review your submission. Once you\'ve finished, please click "Submit" at the bottom of the page, or click "Preview" to check it again.</p>';
// Keep a new image outside the web root until the story is saved;