Last active
June 8, 2018 06:39
-
-
Save landzz/9d0c0ce752f792cec433260e8d06608a to your computer and use it in GitHub Desktop.
php curl get function
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
<?php | |
if ( ! function_exists('getCurlGet')){ | |
function getCurlGet($_url='', $_param=array()){ | |
if($_url !=''){ | |
$curlObj = curl_init(); | |
curl_setopt($curlObj, CURLOPT_URL, $_url.'?'.http_build_query($_param) ); | |
//curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false); | |
//curl_setopt($curlObj, CURLOPT_SSLVERSION, 1); | |
//curl_setopt($curlObj, CURLOPT_POST, true); | |
curl_setopt($curlObj, CURLOPT_HEADER, true); | |
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true); | |
//curl_setopt($curlObj, CURLOPT_POSTFIELDS, http_build_query($_param)); | |
$response = curl_exec($curlObj); | |
$_json = json_decode($response,true); | |
curl_close($curlObj); | |
$curlObj = null; | |
return array( | |
'response' => $response | |
,'json' => $_json | |
); | |
}else{ | |
return false; | |
} | |
} | |
} | |
//sample | |
$_url = 'url'; | |
// parameter | |
$_send_param = array( | |
'param1' => 'param1' | |
,'param2' => 'param2' | |
); | |
$_tmp = getCurlGet($_url, $_send_param); | |
$_response = $_tmp['response']; | |
$_json = $_tmp['json']; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment