You are here

public function CurlPost::submit in reCAPTCHA 6.2

Same name and namespace in other branches
  1. 8.2 recaptcha-php/src/ReCaptcha/RequestMethod/CurlPost.php \ReCaptcha\RequestMethod\CurlPost::submit()
  2. 7.2 recaptcha-php/src/ReCaptcha/RequestMethod/CurlPost.php \ReCaptcha\RequestMethod\CurlPost::submit()

Submit the cURL request with the specified parameters.

Parameters

RequestParameters $params Request parameters:

Return value

string Body of the reCAPTCHA response

Overrides RequestMethod::submit

File

recaptcha-php/src/ReCaptcha/RequestMethod/CurlPost.php, line 66

Class

CurlPost
Sends cURL request to the reCAPTCHA service. Note: this requires the cURL extension to be enabled in PHP

Namespace

ReCaptcha\RequestMethod

Code

public function submit(RequestParameters $params) {
  $handle = $this->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,
  );
  $this->curl
    ->setoptArray($handle, $options);
  $response = $this->curl
    ->exec($handle);
  $this->curl
    ->close($handle);
  return $response;
}