Skip to content

Instantly share code, notes, and snippets.

@SebbeJohansson
Last active September 26, 2018 08:40
Show Gist options
  • Save SebbeJohansson/3eeb1bff837141a927a568b09b28e523 to your computer and use it in GitHub Desktop.
Save SebbeJohansson/3eeb1bff837141a927a568b09b28e523 to your computer and use it in GitHub Desktop.
cURL execution function. - Old version.
/**
* 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