美工统筹SEO,为企业电子商务营销助力!
php接纳curl仿照登录大师网宣布静态的体例
一佰互联网站建造(www.taishanly.com) 宣布日期 2020-04-28 13:46:29 阅读数: 104
本文实例报告了php接纳curl仿照登录大师网宣布静态的体例。分享给大师供大师参考。详细完成体例以下:
说到php中仿照登录良多人第临时候会想到curl函数系列了,这个没错本例子也是利用curl仿照登录以后再停止静态宣布,道理也简略咱们只需抓取大师网的登录信息,而后再由curl post登录数据上去就能够了。
详细代码以下:
复制代码 代码以下:$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;
//婚配用户的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;
//宣布信息
$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 "宣布胜利!";
}else{
echo "shit !!!";
}
最初就宣布胜利了,固然后面的数据库须要本身写一个吧,很是的简略的一个记实库也是你要宣布的信息。录数据上去就能够了。
但愿本文所述对大师的PHP法式设想有所赞助。