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]  view plain  copy
    1. print_r(file_get_contents('http://www.baidu.com'));  
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM