PHP uses curl to imitate the way to publish the dynamic _php technique

Source: Internet
Author: User
Tags curl

The example of this article is about PHP using curl to imitate the way of publishing dynamic. Share to everyone for your reference. The implementation methods are as follows:

When it comes to imitating logins in PHP, many people think of the first time Curl function series, this is true This example is also used curl imitate login after the dynamic release, the principle is simple we just crawl Renren login information, and then by the Curl Post login data up on it.

The specific code is as follows:

Copy Code code 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 User 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;
Publishing 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 "Publish successfully!" ";
}else{
echo "Shit!!!";
}

Finally published successfully, of course, the previous database needs to write a bar, very simple a record library is also the information you want to publish. Record the data to go up on it.

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.