PHP - CURL using HTTPS [closed]



PHP Snippet 1:

  curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cert/file/cacert.pem');

PHP Snippet 2:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $basicAuthUrl);
    $header = array();
    $header[] = 'Content-length: 29';
    $header[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
    $header[] = 'Authorization: Basic ' . $keyAndSecretEncoded;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);      
    curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

    $result = curl_exec($ch);
    curl_close($ch);

PHP Snippet 3:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

PHP Snippet 4:

function disp($opts,$var){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt_array($ch, $opts);
  $raw_resp = curl_exec($ch);
  print_r($raw_resp);
  curl_close($ch);
}