You are here

public function Post::submit in reCAPTCHA 8.2

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

Submit the POST 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/Post.php, line 60

Class

Post
Sends POST requests to the reCAPTCHA service.

Namespace

ReCaptcha\RequestMethod

Code

public function submit(RequestParameters $params) {
  $options = array(
    'http' => array(
      'header' => "Content-type: application/x-www-form-urlencoded\r\n",
      'method' => 'POST',
      'content' => $params
        ->toQueryString(),
      // Force the peer to validate (not needed in 5.6.0+, but still works)
      'verify_peer' => true,
    ),
  );
  $context = stream_context_create($options);
  $response = file_get_contents($this->siteVerifyUrl, false, $context);
  if ($response !== false) {
    return $response;
  }
  return '{"success": false, "error-codes": ["' . ReCaptcha::E_CONNECTION_FAILED . '"]}';
}