php funciton mycurl

來源:互聯網
上載者:User

標籤:http   io   os   ar   檔案   資料   cti   on   c   

/** +---------------------------------------------------------- * CURL +---------------------------------------------------------- * @param string$url 請求的URL * @param string|array$post POST資料  * @param string|array$cookie COOKIE資料 * @param string$cookieFile 記錄COOKIE的檔案名稱 * @param string$referer 來源頁 +---------------------------------------------------------- * @return string +---------------------------------------------------------- */function mycurl($url ,$post=‘‘ ,$cookie=‘‘ ,$cookieFile=‘‘ ,$referer=‘‘){    $curl = curl_init();    $userAgent = ‘Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0‘;    $userAgent = empty($userAgent)?$_SERVER[‘HTTP_USER_AGENT‘]:$userAgent;    curl_setopt($curl, CURLOPT_URL, $url);    curl_setopt($curl, CURLOPT_TIMEOUT, 5);//cURL允許執行的最長秒數    curl_setopt($curl, CURLOPT_HEADER, 0);//將標頭檔的資訊作為資料流輸出    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//true 以檔案流形式返回;  false 直接輸出;    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);//是否擷取重新導向的資訊    curl_setopt($curl, CURLOPT_MAXREDIRS, 5);//重新導向最大次數    curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);//HTTP請求中User-Agent: "部分的內容    if($referer){    curl_setopt($curl, CURLOPT_REFERER, $referer);    }else{    curl_setopt($curl, CURLOPT_AUTOREFERER, 1);    }    if($post){    curl_setopt($curl, CURLOPT_POST, 1);    curl_setopt($curl, CURLOPT_POSTFIELDS, $post);    }    if($cookieFile){    $cookieFile = dirname(__FILE__).DIRECTORY_SEPARATOR.$cookieFile;    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieFile);//包含cookie資料的檔案名稱    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieFile);//串連結束後儲存cookie資訊的檔案    }    if($cookie){    curl_setopt($curl, CURLOPT_COOKIE, $cookie);//HTTP請求中"Cookie: "部分的內容    }    $result = curl_exec($curl);    if(curl_errno($curl))echo ‘<pre><b>ERROR:</b><br />‘.curl_error($curl).‘</pre>‘;    curl_close($curl);    return $result;}



php funciton mycurl

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.