Skip to content

Instantly share code, notes, and snippets.

@landzz
Last active June 8, 2018 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save landzz/9d0c0ce752f792cec433260e8d06608a to your computer and use it in GitHub Desktop.
Save landzz/9d0c0ce752f792cec433260e8d06608a to your computer and use it in GitHub Desktop.
php curl get function
<?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