getBootstrap()->getResource('settings'); $request = Front::getInstance()->getRequest(); $response = $request->getParam('g-recaptcha-response'); if ($response == null || strlen($response) == 0) { return false; } $json = $this->_post(array( 'secret' => $settings['recaptcha_private_key'], 'remoteip' => $_SERVER['REMOTE_ADDR'], 'response' => $response )); $result = json_decode($json, true); if (isset($result['success']) && $result['success'] == true) { return true; } return false; } /** * Submits an HTTP POST to a reCAPTCHA server * * @param array $data * * @return array response */ protected function _post(array $data) { $peerKey = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data, '', '&'), // Force the peer to validate (not needed in 5.6.0+, but still works 'verify_peer' => true, // Force the peer validation to use www.google.com $peerKey => 'www.google.com', ), ); $context = stream_context_create($options); return file_get_contents(self::VERIFY_SERVER, false, $context); } }