Esempio n. 1
0
 /**
  * Submit the POST request with the specified parameters.
  *
  * @param RequestParameters $params Request parameters
  * @return string Body of the reCAPTCHA response
  */
 public function submit(RequestParameters $params)
 {
     $errno = 0;
     $errstr = '';
     if (false === $this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30)) {
         return self::BAD_REQUEST;
     }
     $content = $params->toQueryString();
     $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n";
     $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n";
     $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $request .= "Content-length: " . strlen($content) . "\r\n";
     $request .= "Connection: close\r\n\r\n";
     $request .= $content . "\r\n\r\n";
     $this->socket->fwrite($request);
     $response = '';
     while (!$this->socket->feof()) {
         $response .= $this->socket->fgets(4096);
     }
     $this->socket->fclose();
     if (0 !== strpos($response, 'HTTP/1.1 200 OK')) {
         return self::BAD_RESPONSE;
     }
     $parts = preg_split("#\n\\s*\n#Uis", $response);
     return $parts[1];
 }
Esempio n. 2
0
 /**
  * Submit the cURL request with the specified parameters.
  *
  * @param RequestParameters $params Request parameters
  * @return string Body of the reCAPTCHA response
  */
 public function submit(RequestParameters $params)
 {
     $handle = curl_init(self::SITE_VERIFY_URL);
     $options = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $params->toQueryString(), CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'), CURLINFO_HEADER_OUT => false, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => true);
     curl_setopt_array($handle, $options);
     $response = curl_exec($handle);
     curl_close($handle);
     return $response;
 }
Esempio n. 3
0
 /**
  * Submit the POST request with the specified parameters.
  *
  * @param RequestParameters $params
  *   Request parameters
  *
  * @return string
  *   Body of the reCAPTCHA response
  */
 public function submit(RequestParameters $params)
 {
     try {
         $options = ['headers' => ['Content-type' => 'application/x-www-form-urlencoded'], 'body' => $params->toQueryString()];
         $response = \Drupal::httpClient()->post(self::SITE_VERIFY_URL, $options);
     } catch (RequestException $exception) {
         \Drupal::logger('reCAPTCHA web service')->error($exception);
     }
     return (string) $response->getBody();
 }
Esempio n. 4
0
 /**
  * Submit the POST request with the specified parameters.
  *
  * @param RequestParameters $params Request parameters
  *
  * @return string Body of the reCAPTCHA response
  */
 public function submit(RequestParameters $params)
 {
     /*
      * PHP 5.6.0 changed the way you specify the peer name for SSL context options.
      * Using "CN_name" will still work, but it will raise deprecated errors.
      */
     $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
     $options = ['http' => ['header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => $params->toQueryString(), 'verify_peer' => true, $peer_key => 'www.google.com']];
     $context = stream_context_create($options);
     return file_get_contents(self::SITE_VERIFY_URL, false, $context);
 }
Esempio n. 5
0
 /**
  * Submit the POST request with the specified parameters.
  *
  * @param RequestParameters $params Request parameters
  * @return string Body of the reCAPTCHA response
  */
 public function submit(RequestParameters $params)
 {
     /**
      * PHP 5.6.0 changed the way you specify the peer name for SSL context options.
      * Using "CN_name" will still work, but it will raise deprecated errors.
      */
     $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
     $auth = base64_encode('tenfialho:qawsQAWS');
     $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n Proxy-Authorization: Basic {$auth}\r\n", 'method' => 'POST', 'content' => $params->toQueryString(), 'verify_peer' => true, 'proxy' => 'tcp://10.100.52.4:3128', 'request_fulluri' => true, $peer_key => 'www.google.com'));
     $context = stream_context_create($options);
     return file_get_contents(self::SITE_VERIFY_URL, false, $context);
 }
 /**
  * Submit the POST request with the specified parameters.
  *
  * @param RequestParameters $params Request parameters
  * @return string Body of the reCAPTCHA response
  */
 public function submit(RequestParameters $params)
 {
     $options = array('headers' => array('Content-type' => 'application/x-www-form-urlencoded'), 'method' => 'POST', 'data' => $params->toQueryString());
     $response = drupal_http_request(self::SITE_VERIFY_URL, $options);
     return isset($response->data) ? $response->data : '';
 }