$secretKey, 'response' => $_POST['g-recaptcha-response']]; $options = [ 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($vars) ] ]; $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) { logNewMessage(LOG_ERR, 'reCAPTCHA validation failed, invalid server response.'); return false; } $responseJSON = json_decode($result); logNewMessage(LOG_DEBUG, "ReCAPTCHA result: " . $result); return $responseJSON->{'success'} === true; } } /** * Creates a Google reCAPTCHA element. * * @package LAM\PLUGINS\CAPTCHA */ class htmlReCAPTCHA extends htmlElement { /** site key */ private string $key; /** * Constructor. * * @param string $key site key */ public function __construct(string $key) { $this->key = htmlspecialchars($key); } /** * {@inheritDoc} */ public function generateHTML($module, $input, $values, $restricted): array { $script = new htmlScript('https://www.google.com/recaptcha/api.js'); $script->generateHTML($module, $input, $values, $restricted); echo '
'; return []; } }