当前位置:首页 > PHP教程 > php应用 > 列表

php curl模仿登录人人网发布动态实例

发布:smiling 来源: PHP粉丝网  添加日期:2015-04-11 16:22:28 浏览: 评论:0 

说到php中模仿登录很多人第一时间会想到curl函数系列了,这个没错本例子也是使用curl模仿登录之后再进行动态发布,原理也简单我们只要抓取人人网的登录信息,然后再由curl post登录数据上去就可以了,具体代码如下.

  1. $rconfig = pdo_fetch("SELECT * FROM ".tablename("eduTwo_renren")." WHERE weid = :weid",array(':weid'=>$_W['weid'])); 
  2.  
  3. $cookie_file = dirname(__FILE__)."/renren.cookie"
  4. $login_url = 'http://passport.renren.com/PLogin.do'
  5. $post_fields['email'] = $rconfig['rusername']; 
  6. $post_fields['password'] = $rconfig['rpassword']; 
  7. $post_fields['origURL'] = 'http%3A%2F%2Fhome.renren.com%2FHome.do'
  8. $post_fields['domain'] = 'renren.com'
  9.  
  10. $ch = curl_init($login_url); 
  11. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5'); 
  12. curl_setopt($ch, CURLOPT_HEADER, 0); 
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  14. curl_setopt($ch, CURLOPT_MAXREDIRS, 1); 
  15. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
  16. curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 
  17. curl_setopt($ch, CURLOPT_POST, 1); 
  18. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
  19. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); 
  20. $content = curl_exec($ch); 
  21. $info = curl_getinfo($ch); 
  22. curl_close($ch); 
  23. //var_dump($info);exit; 
  24. //匹配用户的ID 
  25. $send_url='http://www.renren.com/home'
  26. $ch = curl_init($send_url); 
  27. curl_setopt($ch, CURLOPT_HEADER, 0); 
  28. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  29. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
  30. curl_exec($ch); 
  31. $info = curl_getinfo($ch); 
  32. curl_close($ch); 
  33.  
  34.      
  35. //$uid = "305115027"; 
  36. //获取token和rtk 
  37. $send_url=$info['redirect_url']; 
  38. $ch = curl_init($send_url); 
  39. curl_setopt($ch, CURLOPT_HEADER, 0); 
  40. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  41. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
  42. $tmp = curl_exec($ch); 
  43. curl_close($ch); 
  44. preg_match_all("/get_check:'(.*?)',get_check_x:'(.*?)',/is",$tmp,$arr); 
  45. preg_match_all("/'ruid':'(.*?)',/is",$tmp,$utmp); 
  46. //var_dump($utmp);exit; 
  47. $token = $arr[1][0];//1121558104 
  48. $rtk = $arr[2][0];//e9a9cb2 
  49. $uid = $utmp[1][0]; 
  50. //echo $token;exit; 
  51. //发布信息 
  52. $poststr['content'] = $_GPC['content'].$rconfig['tail']; 
  53. $poststr['withInfo'] = '{"wpath":[]}'
  54. $poststr['hostid:'] = $uid
  55. $poststr['privacyParams'] = '{"sourceControl": 99}'
  56. $poststr['requestToken'] = $token
  57. $poststr['_rtk'] = $rtk
  58. $poststr['channel'] = "renren"
  59. $head = array
  60.  'Referer:http://shell.renren.com/ajaxproxy.htm'
  61.  'X-Requested-With:XMLHttpRequest'
  62. ); 
  63. $ch = curl_init("http://shell.renren.com/{$uid}/status"); 
  64. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5'); 
  65. curl_setopt($ch,CURLOPT_HTTPHEADER,$head); 
  66. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  67. curl_setopt($ch, CURLOPT_MAXREDIRS, 1); 
  68. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
  69. curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 
  70. curl_setopt($ch, CURLOPT_POST, 1); 
  71. curl_setopt($ch, CURLOPT_POSTFIELDS, $poststr); 
  72. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
  73. $content = curl_exec($ch);//开源软件:phpfensi.com 
  74. curl_close($ch); 
  75. //echo $content;exit; 
  76. $data = json_decode($content,true); 
  77. if($data["code"] == "0"){ 
  78.  echo "发布成功!"
  79. }else
  80.  echo "shit !!!"

最后就发布成功了,当然前面的数据库大写自己写一个吧,非常的简单的一个记录库也是你要发布的信息.

Tags: curl模仿登录 php发布动态

分享到: