I've got this piece of code to launch queries with curl:
function curl_query($full_url, $username, $password, $payload) {
$additionalHeaders = "";
$process = curl_init($full_url);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', $additionalHeaders));
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, $payload);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($process, CURLOPT_MAXREDIRS, 4);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
$return = curl_exec($process);
if ($return === false) {
error_log("CURL error ".curl_error($process));
}
return $return;
}
The option CURLOPT_SSL_VERIFYPEER is set to false so I can read pages with self-signed certificates. However when I execute this code against an https URL I get an error:
CURL error SSL: certificate subject name 'localhost' does not match target host name '192.168.1.1',
I run this code on a CentOS 5 server with php53 package installed.
Thanks in advance
Solution: If when you login to your CPanel you can verify that the cURL support is enabled but it is not working then your server IP might be banned. If it isn't please re-check the firewall configuration with your server, as it might an issue there that is causing the problem.
libcurl performs peer SSL certificate verification by default. This is done by using a CA certificate store that the SSL library can use to make sure the peer's server certificate is valid.
Parameters ¶ A cURL handle returned by curl_init(). The CURLOPT_XXX option to set. The value to be set on option .
cURL is a PHP library and command-line tool (similar to wget) that allows you to send and receive files over HTTP and FTP. You can use proxies, pass data over SSL connections, set cookies, and even get files that are protected by a login.
Add the option CURLOPT_SSL_VERIFYHOST
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, FALSE);
I realized, that the english version of the PHP documentation missing this important information:
(translated from the german version of the PHP manual)
CURLOPT_SSL_VERIFYHOST has to be set to true or false if CURLOPT_SSL_VERIFYPEER has been deactivated.
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($process,CURLOPT_SSL_VERIFYHOST, FALSE);
ADD THIS TO LINES WILL HELP
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With