php采用curl模仿登錄人人網(wǎng)發(fā)布動(dòng)態(tài)的方法
本文實(shí)例講述了php采用curl模仿登錄人人網(wǎng)發(fā)布動(dòng)態(tài)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
說(shuō)到php中模仿登錄很多人第一時(shí)間會(huì)想到curl函數(shù)系列了,這個(gè)沒(méi)錯(cuò)本例子也是使用curl模仿登錄之后再進(jìn)行動(dòng)態(tài)發(fā)布,原理也簡(jiǎn)單我們只要抓取人人網(wǎng)的登錄信息,然后再由curl post登錄數(shù)據(jù)上去就可以了。
具體代碼如下:
$cookie_file = dirname(__FILE__)."/renren.cookie";
$login_url = 'http://passport.renren.com/PLogin.do';
$post_fields['email'] = $rconfig['rusername'];
$post_fields['password'] = $rconfig['rpassword'];
$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);
$info = curl_getinfo($ch);
curl_close($ch);
//var_dump($info);exit;
//匹配用戶的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);
//$uid = "305115027";
//獲取token和rtk
$send_url=$info['redirect_url'];
$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);
preg_match_all("/'ruid':'(.*?)',/is",$tmp,$utmp);
//var_dump($utmp);exit;
$token = $arr[1][0];//1121558104
$rtk = $arr[2][0];//e9a9cb2
$uid = $utmp[1][0];
//echo $token;exit;
//發(fā)布信息
$poststr['content'] = $_GPC['content'].$rconfig['tail'];
$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);
curl_close($ch);
//echo $content;exit;
$data = json_decode($content,true);
if($data["code"] == "0"){
echo "發(fā)布成功!";
}else{
echo "shit !!!";
}
最后就發(fā)布成功了,當(dāng)然前面的數(shù)據(jù)庫(kù)需要自己寫(xiě)一個(gè)吧,非常的簡(jiǎn)單的一個(gè)記錄庫(kù)也是你要發(fā)布的信息。錄數(shù)據(jù)上去就可以了。
希望本文所述對(duì)大家的PHP程序設(shè)計(jì)有所幫助。
- php 使用curl模擬登錄人人(校內(nèi))網(wǎng)的簡(jiǎn)單實(shí)例
- PHP Curl模擬登錄微信公眾平臺(tái)、新浪微博實(shí)例代碼
- PHP curl模擬登錄帶驗(yàn)證碼的網(wǎng)站
- PHP使用CURL模擬登錄的方法
- PHP讀取CURL模擬登錄時(shí)生成Cookie文件的方法
- PHP使用CURL實(shí)現(xiàn)對(duì)帶有驗(yàn)證碼的網(wǎng)站進(jìn)行模擬登錄的方法
- PHP中使用CURL模擬登錄并獲取數(shù)據(jù)實(shí)例
- PHP CURL獲取cookies模擬登錄的方法
- php使用curl模擬登錄后采集頁(yè)面的例子
- PHP CURL模擬登錄新浪微博抓取頁(yè)面內(nèi)容 基于EaglePHP框架開(kāi)發(fā)
- php curl 登錄163郵箱并抓取郵箱好友列表的代碼(經(jīng)測(cè)試)
- PHP基于curl后臺(tái)遠(yuǎn)程登錄正方教務(wù)系統(tǒng)的方法
相關(guān)文章
PHP編程實(shí)現(xiàn)腳本異步執(zhí)行的方法
這篇文章主要介紹了PHP編程實(shí)現(xiàn)腳本異步執(zhí)行的方法,結(jié)合實(shí)例形式分析了php使用fsockopen()實(shí)現(xiàn)的腳本異步調(diào)用與執(zhí)行操作技巧,需要的朋友可以參考下2017-08-08IIS+fastcgi下PHP運(yùn)行超時(shí)問(wèn)題的解決辦法詳解
本篇文章是對(duì)IIS+fastcgi下PHP運(yùn)行超時(shí)問(wèn)題的解決辦法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06深入apache配置文件httpd.conf的部分參數(shù)說(shuō)明
本篇文章是對(duì)apache配置文件httpd.conf的部分參數(shù)說(shuō)明進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06Cannot modify header information錯(cuò)誤解決方法
Warning: Cannot modify header information - headers already sent by出錯(cuò)的原因2008-10-10php session_start()關(guān)于Cannot send session cache limiter - hea
在windows下編程,當(dāng)使用session_start()方法的時(shí)候,有時(shí)會(huì)報(bào) session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/inpublisher/php1.php:1)這樣的錯(cuò)誤2009-11-11通過(guò)PHP CLI實(shí)現(xiàn)簡(jiǎn)單的數(shù)據(jù)庫(kù)實(shí)時(shí)監(jiān)控調(diào)度
繼續(xù)CLI模式試驗(yàn),這次通過(guò)使用之前的“帶延時(shí)的死循環(huán)”方法,來(lái)實(shí)現(xiàn)個(gè)簡(jiǎn)單的數(shù)據(jù)庫(kù)實(shí)時(shí)監(jiān)控調(diào)度功能。2009-07-07