hanliu's personal blog

任何伟大都会被误解...Wiki Is All 注册 | 登陆
Contact me!

我,在某年某月来到这个世界。于某年某月创建了该BLOG,其间在BLOG的 10 个分类中发表的 513 篇文章被评论了 37 次。

php使用curl通过代理访问网站

php使用curl通过代理访问网站
curl参数很丰富,一般情况下用的不多,所以网上随便搜了一段,懒得自己去看手册了。

 

PHP代码
  1. <?    
  2. function curl_string ($url,$user_agent,$proxy){    
  3.   
  4. $ch = curl_init();    
  5. curl_setopt ($ch, CURLOPT_PROXY, $proxy);    
  6. curl_setopt ($ch, CURLOPT_URL, $url);    
  7. curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);    
  8. curl_setopt ($ch, CURLOPT_COOKIEJAR, "c:\cookie.txt");    
  9. curl_setopt ($ch, CURLOPT_HEADER, 1);    
  10. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);    
  11. curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);    
  12. curl_setopt ($ch, CURLOPT_TIMEOUT, 120);    
  13. $result = curl_exec ($ch);    
  14. curl_close($ch);    
  15. return $result;    
  16.   
  17. }    
  18.   
  19. $url_page = "http://www.google.com";    
  20. $user_agent = "Mozilla/4.0";    
  21. $proxy = "http://127.0.0.1:8000";    
  22. $string = curl_string($url_page,$user_agent,$proxy);    
  23. echo $string;    
  24. ?>  

Tags: php, curl, 代理

« 上一篇 | 下一篇 »

Trackbacks

点击获得Trackback地址,Encode: UTF-8 点击获得Trackback地址,Encode: GB2312 or GBK 点击获得Trackback地址,Encode: BIG5

Leave a Comment

评论内容 (必填):