class CurlPost in reCAPTCHA 6.2
Same name and namespace in other branches
- 8.2 recaptcha-php/src/ReCaptcha/RequestMethod/CurlPost.php \ReCaptcha\RequestMethod\CurlPost
- 7.2 recaptcha-php/src/ReCaptcha/RequestMethod/CurlPost.php \ReCaptcha\RequestMethod\CurlPost
Sends cURL request to the reCAPTCHA service. Note: this requires the cURL extension to be enabled in PHP
Hierarchy
- class \ReCaptcha\RequestMethod\CurlPost implements RequestMethod
Expanded class hierarchy of CurlPost
See also
http://php.net/manual/en/book.curl.php
File
- recaptcha-php/
src/ ReCaptcha/ RequestMethod/ CurlPost.php, line 37
Namespace
ReCaptcha\RequestMethodView source
class CurlPost implements RequestMethod {
/**
* URL to which requests are sent via cURL.
* @const string
*/
const SITE_VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
/**
* Curl connection to the reCAPTCHA service
* @var Curl
*/
private $curl;
public function __construct(Curl $curl = null) {
if (!is_null($curl)) {
$this->curl = $curl;
}
else {
$this->curl = new Curl();
}
}
/**
* 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 = $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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurlPost:: |
private | property | Curl connection to the reCAPTCHA service | |
CurlPost:: |
constant | URL to which requests are sent via cURL. @const string | ||
CurlPost:: |
public | function |
Submit the cURL request with the specified parameters. Overrides RequestMethod:: |
|
CurlPost:: |
public | function |