Home > Backend Development > PHP Tutorial > PHP uses curl to imitate the method of logging into Renren to publish updates, curl Renren_PHP tutorial

PHP uses curl to imitate the method of logging into Renren to publish updates, curl Renren_PHP tutorial

WBOY
Release: 2016-07-13 10:14:48
Original
777 people have browsed it

php uses curl to imitate the method of logging into Renren to publish updates, curl Renren

The example in this article describes how PHP uses curl to imitate logging into Renren to publish updates. Share it with everyone for your reference. The specific implementation method is as follows:

When it comes to simulated login in PHP, many people will immediately think of the curl function series. This is true. This example also uses curl to simulate login and then perform dynamic publishing. The principle is also simple. We only need to grab the login information of Renren. , and then upload the login data via curl post.

The specific code is as follows:

Copy code The code is as follows:
$rconfig = pdo_fetch("SELECT * FROM ".tablename("eduTwo_renren")." WHERE weid = :weid",array(':weid'=>$_W['weid']));

$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;
//Match the user's 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";
//Get token and 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;
//Publish information
$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 "Published successfully!";
}else{
echo "shit!!!";
}

Finally, the release was successful. Of course, you need to write the previous database yourself. A very simple record database is also the information you want to release. Just record the data.

I hope this article will be helpful to everyone’s PHP programming design.

PHP CURL POST simulated user login. I hope you can give the specific code and briefly explain the code

You can check to see if there are other http headers that are not simulated, such as whether Referer and User-Agent can simulate browser values. A complete request is similar to this:
GET /home/pack/ Data/Content? ID = 31,2399,13,30 & asyn = 1 & T = 0.03439752989200834 &_Req_seqid = 0xa982225F06378A HTTP/1.1
*/ *
Accept -Language: zh-cn
Referer: www.baidu. com/
x-requested-with: XMLHttpRequest
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; BTRS123401; InfoPath. 2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; MS-RTC LM 8)
Host: www.baidu.com
Connection: Keep -Alive
Cookie: XCXXXXX

I followed the code of php100, why can’t I simulate login with this php cURL?

$post_fields = 'cktime=31536000&step=2&pwuser=account&pwpwd=password'; try changing the account password to your own, I tried it and it works

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/907836.htmlTechArticlephp uses curl to imitate the method of logging in to Renren to publish updates. Curl Renren This article tells the example of php using curl to imitate How to log in to Renren to post updates. Share it with everyone for your reference. Tool...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template