php curl請求轉發


[php]  view plain  copy
  1. <?php   
  2.    function get_url_content($url){      
  3.     $user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";       
  4.     $ch = curl_init();      
  5.     //curl_setopt ($ch, CURLOPT_PROXY, $proxy);      
  6.     curl_setopt ($ch, CURLOPT_URL, $url);//設置要訪問的IP      
  7.     curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);//模擬用戶使用的瀏覽器       
  8.     @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 ); // 使用自動跳轉        
  9.     curl_setopt ($ch, CURLOPT_TIMEOUT, 60); //設置超時時間      
  10.     curl_setopt ($ch, CURLOPT_AUTOREFERER, 1 ); // 自動設置Referer        
  11.     curl_setopt ($ch, CURLOPT_COOKIEJAR, 'c:\cookie.txt');      
  12.     curl_setopt ($ch, CURLOPT_HEADER,0); //顯示返回的HEAD區域的內容      
  13.     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);      
  14.     curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);      
  15.     curl_setopt ($ch, CURLOPT_TIMEOUT, 10);      
  16.     $result = curl_exec($ch);      
  17.     curl_close($ch);      
  18.     return $result;      
  19. }  
  20. print_r(get_url_content('http://www.baidu.com'));  
  21. ?>  

-----------------------------------------------------------------------------------------php

還能夠用下面方式實現請求轉發瀏覽器

 

[php]  view plain  copy
    1. print_r(file_get_contents('http://www.baidu.com'));  
相關文章
相關標籤/搜索