一个封装好的curl函数

常用函数备忘

// 调用方式
get_curl(网址, post需要json_encode编码, $cookie根据实际情况, $isJson 参数是否是json 登录时 写1, $httpheader = [] 额外header);
/**
 * @Author    Mr.F
 * @DateTime  2022-05-05
 * @copyright [www.fyovo.com]
 * @license   [BY-NC-SA/3.0/CN]
 * @version   [1.0]
 * @param     [type]            $url        [请求url]
 * @param     integer           $post       [post请求数据]
 * @param     integer           $cookie     [cookie]
 * @param     integer           $isJson     [是否json格式]
 * @param     array             $httpheader [请求头]
 * @return    [type]                        [description]
 */
function get_curl($url, $post = 0, $cookie = 0, $isJson = 0, $httpheader = []) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//不验证SSL
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//不验证SSL HOST
	if ($isJson) {
		$httpheader[] = "content-type:application/json";
	}
	$httpheader[] = 'user-agent:Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0';

	curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
	if ($post) {
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	}
	if ($cookie) {
		curl_setopt($ch, CURLOPT_COOKIE, $cookie);
	}
	// curl_setopt($ch, CURLOPT_ENCODING, "gzip");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$ret = curl_exec($ch);
	curl_close($ch);
	return $ret;
}

风影OvO

风影OvO, 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA 4.0协议进行授权 | 转载请注明原文链接

留下你的评论

*评论支持代码高亮<pre class="prettyprint linenums">代码</pre>

相关推荐