summaryrefslogtreecommitdiff
path: root/inc/functions.php
diff options
context:
space:
mode:
authorCarson Fleming <cflems@cflems.net>2022-12-12 05:58:56 -0800
committerCarson Fleming <cflems@cflems.net>2022-12-12 05:58:56 -0800
commita8445664e8453ac643f123b43823a6a9df83c421 (patch)
tree25594330d99ab3dd7328771822d87f324a689ff7 /inc/functions.php
parentacef8733bff13217ab3483055e1c0d7297393ba3 (diff)
downloadbulletin-a8445664e8453ac643f123b43823a6a9df83c421.tar.gz
Attempt to verify captcha result
Diffstat (limited to 'inc/functions.php')
-rw-r--r--inc/functions.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/inc/functions.php b/inc/functions.php
index c381ab7..d3aa93e 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -104,4 +104,28 @@ function pwgen ($len) {
$pass .= $alpha[mt_rand(0, $alen-1)];
return $pass;
}
+
+function recaptcha_verify ($response) {
+ global $b_config;
+
+ $endpoint = 'https://google.com/recaptcha/api/siteverify';
+ $data = json_encode(array(
+ 'secret' => $b_config['recaptcha_api_secret'],
+ 'response' => $response,
+ ));
+ $ctx = stream_context_create(array(
+ 'http' => array(
+ 'method' => 'POST',
+ 'header' => 'Content-Type: application/json' . "\r\n"
+ . 'Content-Length: ' . strlen($data) . "\r\n",
+ 'content' => $data
+ )
+ ));
+ $result = file_get_contents($endpoint, false, $ctx);
+ if (!$result) return false;
+ $result = json_decode($result);
+ if (!$result) return false;
+ return isset($result['success']) && isset($result['hostname']) &&
+ $result['success'] && $result['hostname'] == $_SERVER['HTTP_HOST'];
+}
?>