Skip to content

Instantly share code, notes, and snippets.

@landzz
Created June 8, 2018 06:43
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/882ed1a9826928e18a065fa0a532e930 to your computer and use it in GitHub Desktop.
Save landzz/882ed1a9826928e18a065fa0a532e930 to your computer and use it in GitHub Desktop.
php curl post function
<?php
if ( ! function_exists('getCurlPost')){
function getCurlPost($_url='', $_param=array()){
if($_url !=''){
ini_set("memory_limit", "512M");
$_headers = array(
"Content-Type: application/x-www-form-urlencoded; charset=utf-8"
);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $_url );
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlObj, CURLOPT_SSLVERSION, 1);
curl_setopt($curlObj, CURLOPT_POST, true);
curl_setopt($curlObj, CURLOPT_HEADER, false);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $_headers);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, http_build_query($_param));
$response = curl_exec($curlObj);
$_json = array();
$_json = json_decode($response,true);
curl_close($curlObj);
return array(
'response' => $response
,'json' => $_json
);
}else{
return false;
}
}
}
//sample
$_url = 'url';
// parameter
$_send_param = array(
'param1' => 'param1'
,'param2' => 'param2'
);
$_tmp = getCurlPost($_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