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'));  
 

转载于:https://www.cnblogs.com/wanghuaijun/p/5497085.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值