php curl模拟登陆人人网发表状态
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-22 11:29:28 浏览: 评论:0
在php中要实现用户登录我们一般都会到curl模拟登陆功能,下面我就基于php的curl来实现登录人人网,完整的例子希望对各位有帮助,代码如下:
- <?php
- $cookie_file = dirname(__FILE__)."/renren.cookie";
- $login_url = 'http://passport.renren.com/PLogin.do';
- $post_fields['email'] = '';//人人的帐号
- $post_fields['password'] = '';//人人密码
- $post_fields['origURL'] = 'http%3A%2F%2Fhome.renren.com%2FHome.do';
- $post_fields['domain'] = 'renren.com';
- $ch = curl_init($login_url);
- 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');
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
- curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
- $content = curl_exec($ch);
- curl_close($ch);
- //匹配用户的ID
- $send_url='http://www.renren.com/home';
- $ch = curl_init($send_url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
- curl_exec($ch);
- $info = curl_getinfo($ch);
- curl_close($ch);
- //获取用户id
- $tmp = explode('/',$info['redirect_url']);
- $uid = array_pop($tmp);
- unset($tmp);
- //$uid = "305115027";
- //获取token和rtk
- $send_url='http://www.renren.com/'.$uid;
- $ch = curl_init($send_url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
- $tmp = curl_exec($ch);
- curl_close($ch);
- preg_match_all("/get_check:'(.*?)',get_check_x:'(.*?)',/is",$tmp,$arr);
- $token = $arr[1][0];//1121558104
- $rtk = $arr[2][0];//e9a9cb2
- //发布信息
- $poststr['content'] = "这就是一个测试而已!!!";
- $poststr['withInfo'] = '{"wpath":[]}';
- $poststr['hostid:'] = $uid;
- $poststr['privacyParams'] = '{"sourceControl": 99}';
- $poststr['requestToken'] = $token;
- $poststr['_rtk'] = $rtk;
- $poststr['channel'] = "renren";
- $head = array(
- 'Referer:http://shell.renren.com/ajaxproxy.htm',
- 'X-Requested-With:XMLHttpRequest',
- );
- $ch = curl_init("http://shell.renren.com/{$uid}/status");
- 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');
- curl_setopt($ch,CURLOPT_HTTPHEADER,$head);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $poststr);
- curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
- $content = curl_exec($ch);//开源代码phpfensi.com
- curl_close($ch);
- $data = json_decode($content,true);
- if($data["code"] == "0"){
- echo "发布成功!";
- }else{
- echo "shit !!!";
- }
Tags: curl模拟登陆 php发表状态
- 上一篇:php获取QQ头像并显示的例子
- 下一篇:php中防止post提交重复数据
相关文章
- ·php中curl模拟登陆用户百度知道的例子(2014-06-29)
- ·Php CURL模拟登陆论坛并采集数据实例(2014-07-07)
- ·php curl模拟post请求提交数据例子总结(2014-08-28)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)