Created
June 25, 2019 15:36
-
-
Save alexrusin/d77a917cc06d0465783685e55edaecc6 to your computer and use it in GitHub Desktop.
Curl Connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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