PHP uses curl to imitate the method of log in Renren publish dynamic
Speaking of PHP imitation login Many people first think of the Curl function series, this is true This example is also using Curl emulation login After the dynamic release, the principle is simple we just grab Renren's login information, and then by the Curl Post login data up.
The specific code is as follows:
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 tokens 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;
Post 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 "released successfully! ";
}else{
echo "Shit!!!";
}
The final release is successful, of course, the previous database needs to write a bar, a very simple record library is also the information you want to publish. Record the data up on it.
http://www.bkjia.com/PHPjc/907712.html www.bkjia.com true http://www.bkjia.com/PHPjc/907712.html techarticle PHP uses Curl to imitate login Renren to publish a dynamic way to say PHP in imitation login Many people think of the Curl function series The first time, this is true This example is also using Curl emulation login ...