Created
March 30, 2019 14:19
-
-
Save huzoorbux/25bb30c414fa6c7652dfba12f013524f to your computer and use it in GitHub Desktop.
my curl method
This file contains hidden or 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
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