error(self::MISSING_VALUE); return false; } if (empty($value[$this->_RESPONSE])) { $this->error(self::MISSING_VALUE); return false; } if (! extension_loaded('curl')) { $this->error('reCAPTCHA 3 requires the PHP CURL extension'); return false; } //set POST variables $url = self::VERIFY_SERVER; $fields_string = http_build_query([ 'secret' => $this->getPrivkey(), 'response' => $value[$this->_RESPONSE], 'remoteip' => $_SERVER['REMOTE_ADDR'], ]); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = @json_decode(curl_exec($ch), true); if (! is_array($result)) { $this->error(self::ERR_CAPTCHA); return false; } if ($result['success'] == false) { $this->error(self::BAD_CAPTCHA); return false; } // Cache google respnonse to avoid second resubmission on ajax form $_SESSION['recaptcha_cache'][] = $value[$this->_RESPONSE]; return true; } /** * Render captcha * * @return string */ public function render() { $api_server = self::API_SERVER; return << EOF; } /** * Render captcha though Ajax * * @return string */ public function renderAjax() { return << EOF; } }