廢話不多說直接上代碼
復制代碼 代碼如下:
/********************** curl 系列 ***********************/
//直接通過curl方式取得數據(包含POST、HEADER等)
/*
* $url: 如果非數組,則為http;如是數組,則為https
* $header: 頭文件
* $post: post方式提交 array形式
* $cookies: 0默認無cookie,1為設置,2為獲取
*/
public function curl_allinfo($urls, $header = FALSE, $post = FALSE, $cookies = 0) {
$url = is_array($urls) ? $urls['0'] : $urls;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//帶header方式提交
if($header != FALSE){
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
//post提交方式
if($post != FALSE){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if($cookies == 1){
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");
}else if($cookies == 2){
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
}
if(is_array($urls)){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
}