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

php采用curl模仿登录人人网发布动态的方法

发布:smiling 来源: PHP粉丝网  添加日期:2021-04-24 16:19:34 浏览: 评论:0 

这篇文章主要介绍了php采用curl模仿登录人人网发布动态的方法,分析了curl登陆人人网的原理与具体方法,非常具有实用价值,需要的朋友可以参考下

本文实例讲述了php采用curl模仿登录人人网发布动态的方法。分享给大家供大家参考。具体实现方法如下:

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

具体代码如下:

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

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

希望本文所述对大家的PHP程序设计有所帮助。

Tags: curl模仿登录 php登录人人网

分享到: