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'));  
相关文章
相关标签/搜索