Open source reCAPTCHA alternative
<script src="https://captcheck.extinctionrebellion.uk/captcheck.min.js"></script>
Put this in your form where you want the CAPTCHA:
<div class="captcheck_container"></div>
Put this in your server-side form validation (PHP example):
$url = 'https://captcheck.extinctionrebellion.uk/api.php';
$data = [
'session_id' => $_POST['captcheck_session_code'],
'answer_id' => $_POST['captcheck_selected_answer'],
'action' => "verify"
];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$resp = json_decode($result, TRUE);
if (!$resp['result']) {
// Replace with error-handling code
exit("CAPTCHA did not verify:" . $resp['msg']);
} else {
// The CAPTCHA is valid.
exit("CAPTCHA verified!");
}
If you have a strict Content Security Policy, change your div to this:
<div class="captcheck_container" data-stylenonce="your nonce here"></div>