Skip to content

Instantly share code, notes, and snippets.

@alexrusin
Created June 25, 2019 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexrusin/d77a917cc06d0465783685e55edaecc6 to your computer and use it in GitHub Desktop.
Save alexrusin/d77a917cc06d0465783685e55edaecc6 to your computer and use it in GitHub Desktop.
Curl Connection
function makeCURLconnection($postURL, $curlTYPE, $dataToPost = null, $headerPOST = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postURL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, '0');
if($headerPOST){
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerPOST);
}
if($curlTYPE == 'PUT'){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
}
if($curlTYPE == 'DELETE'){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
}
if($curlTYPE == 'POST'){
curl_setopt($ch, CURLOPT_POST, TRUE);
}
if($curlTYPE == 'GET'){
curl_setopt($ch, CURLOPT_POST, 0);
}
if($dataToPost){
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataToPost);
}
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$results = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curlHeader = curl_getinfo($ch, CURLINFO_HEADER_OUT );
curl_close($ch);
$httpCode = intval($httpcode);
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment