Last active
September 26, 2018 08:40
-
-
Save SebbeJohansson/3eeb1bff837141a927a568b09b28e523 to your computer and use it in GitHub Desktop.
cURL execution function. - Old version.
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
/** | |
* Execute a cURL. | |
* | |
* @param $url | |
* @param array $header An array of headers. | |
* @param string $mode Mode for the execution (PUT/GET/POST). | |
* @param string $variables Variables/body to send in execution. String or json. | |
* @return mixed Returns decoded json of return from execution. | |
*/ | |
function executeCURL($url, $header = array(), $mode = "GET", $variables = ""){ | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL,$url); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); | |
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $mode); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $variables); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | |
$content = curl_exec($curl); | |
$array = json_decode($content, true); | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment