E-Multitech Solution

Blog

How to Use php cURL to access HTTPs

Web Developer in Discussion PHP/MySql/HTML

0 Comment

I guess all of you are familiar with cURL that’s why I am not going to explain or say what is cURL how it works and how to use it. Here I am just going to let you know how to make work curl with SSL TLS. If you try calling any url with HTTPS using curl it generally throws many errors like protocol do not support the libcurl or not embedded etc.
First of all you have to check either curl is supported or not on your server you can check it with following codes
if (!function_exists(‘curl_init’)){
die(‘uFF cURL is not enabled or installed!’);
}
Well now how to overcome problems of not getting access to https here is very quick and smart method to fixed this problem.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
So complete codes goes here

So your complete codes look like this

 

function access_curl_with_https($url){

// check if curl is installed or not
if (!function_exists(‘curl_init’)){
die(‘uFF cURL is not enabled or installed!’);
}

// gret lees initial the curl
$ch = curl_init();

// setting up options

// Set URL to call
curl_setopt($ch, CURLOPT_URL, $Url);

curl_setopt($ch, CURLOPT_USERAGENT, “MozillaXYZ/1.0”);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_TIMEOUT, 10);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$output = curl_exec($ch);

curl_close($ch);

return $output;
}
echo curl_download(‘https://abc.com’);

Place this option before curl_exec(): the curl then it will start to works
Thanks

Leave a Comment.

Verify CAPTCHA *