PHP Universal Curl Class, can post/get/file transfer
functionDo_curl ($url,$params=Array(),$upload=false,$type= ' POST '){ $method=Strtoupper($type); if($method= = ' GET ') { $url= "{$url}?" .Http_build_query($params); } $ch=Curl_init (); //$header [] = "user-agent:mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/64.0.3282.140 safari/537.36 "; Define request type//curl_setopt ($ch, Curlopt_httpheader, $header);curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_returntransfer,true); //curl_setopt ($ch, Curlopt_customrequest, $method); Whether to detect whether the server's certificate is issued by an authorized CA that is certified by a formal browsercurl_setopt ($ch, Curlopt_ssl_verifypeer,false); //whether the domain name of the server is detected as consistent with the certificatecurl_setopt ($ch, Curlopt_ssl_verifyhost, 0); //var_dump ($params);d ie; if($method= = ' POST ') { if($upload) {//Set upload file $file=New\curlfile ($upload[' Tmp_name '],$upload[' type '],$upload[' Name ']); $params[$upload[' Get_name '] =$file; } @curl_setopt ($ch, Curlopt_post, 1); @curl_setopt ($ch, Curlopt_postfields,$params); } $result= Curl_exec ($ch); Curl_close ($ch); if($result===NULL||$result===false) { $this->error (' Operation Error! ‘); } Else { return $result; }}
PHP Universal Curl Class