include the Zebra_cURL library
require 'path/to/Zebra_cURL';
instantiate the class
$curl = new Zebra_cURL();
instruct the library to verify peer's SSL certificate
(ignored if request is not made through HTTPS)
$curl->ssl(true);
fetch a page
$curl->get('https://www.somewebsite.com/', create_function('$result', 'print_r("
"); print_r($result);'));
public ssl ( boolean $verify_peer = true, integer $verify_host = 2, mixed $file = false, mixed $path = false ) : void | ||
$verify_peer | boolean | (Optional) Should the peer's certificate be verified by cURL? Default is TRUE. This option can also be set using the {@link option} method and setting CURLOPT_SSL_VERIFYPEER option to the desired value. @param integer $verify_host (Optional) Specifies whether or not to check the existence of a common name in the SSL peer certificate and that it matches with the provided hostname. - 1 to check the existence of a common name in the SSL peer certificate; - 2 to check the existence of a common name and also verify that it matches the hostname provided; in production environments the value of this option should be kept at 2; Default is 2 Support for value 1 removed in cURL 7.28.1 This option can also be set using the {@link option} method and setting CURLOPT_SSL_VERIFYHOST option to the desired value. @param mixed $file (Optional) An absolute path to a file holding one or more certificates to verify the peer with. This only makes sense if CURLOPT_SSL_VERIFYPEER is set to TRUE. Default is FALSE. This option can also be set using the {@link option} method and setting CURLOPT_CAINFO option to the desired value. @param mixed $path (Optional) An absolute path to a directory that holds multiple CA certificates. This only makes sense if CURLOPT_SSL_VERIFYPEER is set to TRUE. Default is FALSE. This option can also be set using the {@link option} method and setting CURLOPT_CAPATH option to the desired value. @return void |
$verify_host | integer | |
$file | mixed | |
$path | mixed | |
return | void |
public function ssl($verify_peer = true, $verify_host = 2, $file = false, $path = false)
{
// set default options
$this->option(array(CURLOPT_SSL_VERIFYPEER => $verify_peer, CURLOPT_SSL_VERIFYHOST => $verify_host));
// if a path to a file holding one or more certificates to verify the peer with was given
if ($file !== false) {
// if file could be found, use it
if (is_file($file)) {
$this->option(CURLOPT_CAINFO, $file);
} else {
trigger_error('File "' . $file . '", holding one or more certificates to verify the peer with, was not found', E_USER_ERROR);
}
}
// if a directory holding multiple CA certificates was given
if ($path !== false) {
// if folder could be found, use it
if (is_dir($path)) {
$this->option(CURLOPT_CAPATH, $path);
} else {
trigger_error('Directory "' . $path . '", holding one or more CA certificates to verify the peer with, was not found', E_USER_ERROR);
}
}
}