標籤:數組 調試 釋放 相關 讀取 length ica span 調用
1 <?php 2 //建立一個新cURL資源 3 $ch = curl_init(); 4 //************************************************************************************ 5 //設定URL和相應的選項 6 //設定 HTTP 頭欄位的數組。格式: array(‘Content-type: text/plain‘, ‘Content-length: 100‘) 7 $headers = array( 8 "content-type: application/x-www-form-urlencoded; charset=gb2312"); 9 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);10 curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com/");11 //************************************************************************************12 //索要上傳的資料 注意:要傳送檔案時,要在檔案名稱前面加上 @ 首碼並使用完整路徑13 $data = array(‘name‘=>‘beauty‘, "upload"=>"@a.zip");14 curl_setopt($ch, CURLOPT_POST, 1);15 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);16 //************************************************************************************17 ////設定curl參數,要求結果是否輸出到螢幕上,為1的時候是不返回到網頁中,0:直接顯示 假設的0換成1的話,那麼接下來的$data就需要echo一下。18 curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);//是否自動顯示返回的資訊 19 //是否顯示返回的http頭資訊20 curl_setopt($ch, CURLOPT_HEADER, 1);21 //************************************************************************************22 23 // 串連結束後,比如,調用 curl_close 後,儲存 cookie 資訊的檔案。 24 curl_setopt($ch,CURLOPT_COOKIEJAR, dirname(__FILE__).‘/cookie.txt‘); 25 //************************************************************************************26 //************************************************************************************27 28 curl_setopt($curl, CURLOPT_POST, 1);//post方式提交 29 curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));//要提交的資訊 30 //************************************************************************************31 32 //允許 cURL 函數執行的最長秒數。 33 curl_setopt($ch, CURLOPT_TIMEOUT, 10);34 //************************************************************************************35 36 curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).‘/cookie.txt‘); //讀取cookie37 //************************************************************************************38 39 //curl_getinfo()函數返回cURL執行後這一請求相關的資訊,這對調試和排錯很有用: 取得對方響應後的資訊40 $info = curl_getinfo($ch);41 //************************************************************************************42 43 // 抓取URL並把它傳遞給瀏覽器44 $res = curl_exec($ch);45 46 // 關閉cURL資源,並且釋放系統資源47 curl_close($ch);48 echo "<pre>";49 print_r($info);50 echo "</pre>";51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 ?>
curl常用功能