美高梅官方网站3045-mgm6608美高梅app下载
php curl模仿登录人人网发布动态实例

php curl模仿登录人人网发布动态实例

作者:mgm6608美高梅app下载    来源:未知    发布时间:2020-02-03 01:29    浏览量:

有的时候我们会用curl模拟提交一些ajax需要提交的数据,其中有的是他自己构建的一些方法,所以呢,就需要我们自己来构建header头来完全模拟,在本次demo中,有提到json,因为有的使用js或者jquery来转化为json的其中,中文不会转义,而代码会,这个参数是在php5.4之后才支持的,大家切记。还有就是这是一个模拟登陆aspx类型的网站,其实原理是一样的,最重要的就是分析好他需要什么参数和数据,而我们怎样构建、获得和组合,万变不离其宗,相信大家都可以的。。。

例子代码

例子, 模拟登陆

$cookie_file=dirname."/cookie.tmp";

 代码如下

 代码如下

$cookie_files=dirname."/cookies.tmp";

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

/**
* 模拟登陆
* $url 请求地址
* $post 需要POST的数据
* $cookie 登陆时取的的COOKIE
* $cookiejar cookie要存到的位置 例如/tmp/test.cookie
* $referer 上页地址
*
**/
function vcurl($url, $post = '', $cookie = '', $cookiejar = '', $referer = ''){
$tmpInfo = '';
//用来存放cookie的文件
//初始化curl
$curl = curl_init();
//设定目标网址
curl_setopt($curl, CURLOPT_URL, $url);
//使用目前所用的浏览器代理
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
//如果有Ref参数,则设置Referer头,否则自动设置Referer头
if($referer) {
curl_setopt($curl, CURLOPT_REFERER, $referer);
} else {
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
}
//如果有post数据参数,则方法为POST,并且设置数据,否则为GET
if($post) {
//发送一个常规的POST请求,默认类型为:application/x-www-form-urlencoded,www.111cn.net表单提交
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
//如果有cookie参数,则设置
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
//如果有cookie文件参数,则设置存取Cookie文件名
if($cookiejar) {
curl_美高梅官方网站3045,setopt($curl, CURLOPT_COOKIEJAR, $cookiejar);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiejar);
}
//如果是302转移,则返回转移后的网址及内容
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
//设置执行的最大秒数
curl_setopt($curl, CURLOPT_TIMEOUT, 100);
//返回内容中是否包含头信息
curl_setopt($curl, CURLOPT_HEADER, 0);
//把返回的结果存在文件或者变量中,而不是直接显示在浏览器
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//执行函数后的返回结果
$tmpInfo = curl_exec($curl);
//如果出错,显示错误信息
if (curl_errno($curl)) {
$tmpInfo = '<pre><b>错误:</b><br />'.curl_error($curl);
}
//关闭curl对象
curl_close($curl);
//返回结果
return $tmpInfo;
}

$headers_login=array("User-Agent"=>"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36");

$cookie_file = dirname(__FILE__)."/renren.cookie";

例子、soap

$post_url="";

$login_url = '';
$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';

 

$post=array("BaseTextBox1"=>"nmdr88","BaseTextBox2"=>"nmdr880217","__VIEWSTATE"=>"/wEPDwUJNjUzMTkwMTE0ZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAQUOTXlJbWFnZUJ1dHRvbjFg33EbGTscw5RfbydKFvsibpHfug==","__VIEWSTATEGENERATOR"=>"9B5805F3","MyImageButton1.x"=>0,"MyImageButton1.y"=>0);

$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='';
$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);

 代码如下

$curl=curl_init();

   
//$uid = "305115027";
//获取token和rtk

function vcurlsoap($url, $SoapRequest, $SoapAction) {
$ch = curl_init (); //initiate the curl session
curl_setopt ( $ch, CURLOPT_URL, $url ); //set to url to post to
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return data in a variable
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $SoapRequest ); // post the xml
curl_setopt ( $ch, CURLOPT_TIMEOUT, 60 ); // set timeout in seconds
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
$header = array ("Content-Type: text/xml" );
$header [] = "Content-Length: ".strlen($SoapRequest);
if (! is_null ( $SoapAction ))
$header [] = 'SOAPAction: "' . $SoapAction . '"';
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
$xmlResponse = curl_exec ( $ch );
curl_close ( $ch );
return $xmlResponse;
}

curl_setopt($curl,CURLOPT_URL,"");

$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";

curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);

$head = array(
 'Referer:',
 'X-Requested-With:XMLHttpRequest',
);
$ch = curl_init("");
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 !!!";
}

curl_setopt($curl,CURLOPT_COOKIEJAR,$cookie_file);

最后就发布成功了,当然前面的数据库大写自己写一个吧,非常的简单的一个记录库也是你要发布的信息哦。

curl_setopt($curl,CURLOPT_PROXY,'127.0.0.1:8888');

原文来自:  

$contents=curl_exec;

 

curl_close;

var_dump($contents);die;

$curl=curl_init();

curl_setopt($curl,CURLOPT_URL,$post_url);

curl_setopt($curl,CURLOPT_HTTPHEADER,$headers_login);

curl_setopt($curl,CURLOPT_HEADER,0);

curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);

curl_setopt($curl,CURLOPT_TIMEOUT,30);

下一篇:没有了
友情链接: 网站地图
Copyright © 2015-2019 http://www.zen-40.com. mgm美高梅有限公司 版权所有