Skip to content

Instantly share code, notes, and snippets.

@huzoorbux
Created March 30, 2019 14:19
Show Gist options
  • Save huzoorbux/25bb30c414fa6c7652dfba12f013524f to your computer and use it in GitHub Desktop.
Save huzoorbux/25bb30c414fa6c7652dfba12f013524f to your computer and use it in GitHub Desktop.
my curl method
public function runCurl($url, $post = null, $headers = null, $delete = null){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $post == null ? 0 : 1);
if($post != null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if($delete != null) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "$delete");
}
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
if($headers != null) {
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($http_code >= 400) {
return $response;
}
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment