You must say:"Yes" or "All right"! 注册 | 登陆

PHP CURL模拟GET及POST函数


PHP代码
  1. <?php   
  2. function vcurl($url$post = ''$cookie = ''$cookiejar = ''$referer = ''){   
  3.     $tmpInfo = '';   
  4.     $cookiepath = getcwd().'./'.$cookiejar;   
  5.     $curl = curl_init();   
  6.     curl_setopt($curl, CURLOPT_URL, $url);   
  7.     curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);   
  8.     if($referer) {   
  9.     curl_setopt($curl, CURLOPT_REFERER, $referer);   
  10.     } else {   
  11.     curl_setopt($curl, CURLOPT_AUTOREFERER, 1);    
  12.     }   
  13.     if($post) {   
  14.     curl_setopt($curl, CURLOPT_POST, 1);    
  15.     curl_setopt($curl, CURLOPT_POSTFIELDS, $post);   
  16.     }   
  17.     if($cookie) {   
  18.     curl_setopt($curl, CURLOPT_COOKIE, $cookie);   
  19.     }   
  20.     if($cookiejar) {   
  21.     curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiepath);   
  22.     curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiepath);   
  23.     }   
  24.     //curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);   
  25.     curl_setopt($curl, CURLOPT_TIMEOUT, 100);   
  26.     curl_setopt($curl, CURLOPT_HEADER, 0);   
  27.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   
  28.     $tmpInfo = curl_exec($curl);   
  29.     if (curl_errno($curl)) {   
  30.        echo '<pre><b>错误:</b><br />'.curl_error($curl);   
  31.     }   
  32.     curl_close($curl);   
  33.     return $tmpInfo;   
  34. }   
  35. ?>  

新版函数,更加简洁了,HOHO!

Tags: php, curl

« 上一篇 | 下一篇 »

只显示10条记录相关文章

6条记录访客评论

很不错,最近一直在学CURL。我想请教 下怎么模拟登陆有验证码的网站 那?

Post by nestcut on 2010, August 26, 2:12 PM 引用此文发表评论 #1

<a target=\\\"_blank\\\" href=\\\"http://www.taobaowenda.com/\\\">淘宝问答</a>更加简洁了,HOHO!

Post by 淘宝问答 on 2010, July 26, 3:28 PM 引用此文发表评论 #2

我留下QQ吧:5121565

Post by siting on 2010, June 7, 11:26 PM 引用此文发表评论 #3

孤魂兄,你制作出wordpress3.02B的火车WEB发布模块了吗?
我这2天一直在弄,可以获取分类列表,但测试发布不成功。
有时间请指教一下:
_wpnonce=[登录随机值1]&_wp_http_referer/wp-admin/Fpost-new.php&user_ID=1&action=post&originalaction=post&post_author=&post_type=post&original_post_status=draft&referredby=redo&_wp_original_http_referer=/wp-admin/post-new.php&auto_draft=&post_ID=&autosavenonce=&meta-box-order-nonce=&closedpostboxesnonce=&wp-preview=&hidden_post_status=draft&post_status=draft&hidden_post_password=&hidden_post_visibility=public&visibility=public&post_password=&mm=&jj=&aa=&hh=&mn=&ss=&hidden_mm=&cur_mm=&hidden_jj=&cur_jj=&hidden_aa=&cur_aa=&hidden_hh=&cur_hh=&hidden_mn=&cur_mn=&original_publish=Publish&publish=Publish&post_category[]=0&post_category[]=[分类ID]&newcategory=New+Category+Name&newcategory_parent=-1&_ajax_nonce=&tax_input[post_tag]=[标签:TAG]&newtag[post_tag]=&post_title=[标签:标题]&samplepermalinknonce=&content=[标签:内容]&excerpt=&trackback_url=&metakeyinput=&metavalue=&_ajax_nonce=&advanced_view=1&comment_status=open&ping_status=open&post_name=

Post by siting on 2010, June 7, 11:25 PM 引用此文发表评论 #4

不错!俺也要学php

Post by 王开兴 on 2010, January 23, 12:24 AM 引用此文发表评论 #5

好软网
www.haoruan.net

想和博主交换链接~!

可以的话麻烦到好软网留言给我~! 谢谢

Post by 好软网 on 2010, January 20, 9:59 PM 引用此文发表评论 #6


发表评论

评论内容 (必填):