public function CurlPost::submit in reCAPTCHA 8.2
Same name and namespace in other branches
- 6.2 recaptcha-php/src/ReCaptcha/RequestMethod/CurlPost.php \ReCaptcha\RequestMethod\CurlPost::submit()
- 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 70
Class
- CurlPost
- Sends cURL request to the reCAPTCHA service. Note: this requires the cURL extension to be enabled in PHP
Namespace
ReCaptcha\RequestMethodCode
public function submit(RequestParameters $params) {
$handle = $this->curl
->init($this->siteVerifyUrl);
$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);
if ($response !== false) {
return $response;
}
return '{"success": false, "error-codes": ["' . ReCaptcha::E_CONNECTION_FAILED . '"]}';
}