我们这里是一个简单的利用php来php 模拟登录后再到qq空间发送文章的一个简单的程序,有需要的朋友可以参考,或改进可以给我意见,代码如下:
$method,
'header' => $header,
'content' => $postdata
);
//生成流
$context = stream_context_create($opts);
//发送请求,获取源码
$yuanma = file_get_contents($url, false, $context);
//是否需要保存cookie到文件,$cookiefile不空时
if ($cookiefile != '') {
echo '需要保存cookie
';
//判断保存文件存在,不存在创建
if (!file_exists($cookiefile)) {
file_put_contents($cookiefile, '');
}
//获取cookie,保存起来
$response = implode("rn", $http_response_header);
//用正则匹配cookie
$zengze = "/Set-Cookie:(.*?)rn/";
preg_match_all($zengze, $response, $cookie_arr);
//存在匹配,保存
if (!emptyempty($cookie_arr[1])) {
$cookiestr = implode(';', $cookie_arr[1]);
file_put_contents($cookiefile, $cookiestr);
echo '成功保存cookie
';
} else echo '没有匹配到cookie
';
} //end if($cookiefile!='')
//返回源码
return $yuanma;
} //end function request($url,$referer,$postdata,$cookie,$cookiefile)
//获得当前的脚本网址
function GetCurUrl() {
if (!emptyempty($_SERVER["REQUEST_URI"])) {
$scriptName = $_SERVER["REQUEST_URI"];
$nowurl = $scriptName;
} else {
$scriptName = $_SERVER["PHP_SELF"];
if (emptyempty($_SERVER["QUERY_STRING"])) {
$nowurl = $scriptName;
} else {
$nowurl = $scriptName . "?" . $_SERVER["QUERY_STRING"];
}
}
return $nowurl;
}
//获得当前文件名
$nowurl = GetCurUrl();
//echo $nowurl;
//表单输出,没有提交时
if (!isset($_POST['qq'])) {
echo '';
die();
}
/*
提交参数说明:
$_POST['qq']---用户QQ
$_POST['g_tk']--这个参数很关键,获得这个参数,需要抓下发表时提交的post地址后面调用的g_tk=1276354485,
路POST http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=1276354485里的g_tk=1276354485
$_POST['title']---文章标题,不得空
$_POST['content']---文章内容,不得空
*/
header('Content-Type:text/html;charset=gb2312');
set_time_limit(0);
//ob_end_clean();
//ob_start();
//获取cookie文件,不存在创建,并退出程序
$cookiefile = dirname(__FILE__) . 'qq_cookie.txt';
if (!file_exists($cookiefile)) {
echo 'qq_cookie.txt不存在,自动创建,请填写抓包的cookie'; file_put_contents($cookiefile, ''); die('程序退出'); } //存在,读取cookie else { $cookie = file_get_contents($cookiefile); //登录cookie //$cookie=urlencode($cookie); } //echo 'cookie:'.$cookie.'
'; //构成发表页,post数据等的重要信息 //qq号码 if (emptyempty($_POST['qq']) || preg_match('/[^0-9]/is', $_POST['qq'])) die('qq号码有误,必须数字'); else $qq = $_POST['qq']; //qq号 if (emptyempty($_POST['g_tk']) || preg_match('/[^0-9]/is', $_POST['g_tk'])) die('post重要参数g_tk不合法,必须数字,请使用抓包的值'); $g_tk = $_POST['g_tk']; $title = emptyempty($_POST['title']) ? die('标题不得空') : $_POST['title']; //文章标题 $content = emptyempty($_POST['content']) ? die('内容不得空') : $_POST['content']; //内容 $category = '个人日记'; //分类 $fabiao = 'http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=' . $g_tk; //发表处理页 $referer = 'http://ctc.qzs.qq.com/qzone/v5/toolpages/fp_gbk.html'; //来源页 $r1 = 'http://user.qzone.qq.com/' . $qq . '/infocenter'; //列表访问来源页 $postdata = 'uin=' . $qq . '&category=' . urlencode($category) . '&title=' . urlencode($title) . '&content=' . urlencode($content) . '&html=' . urlencode('
'; else echo '发表失败:右键查看源码,可以看到具体错误' . $yuanma; ?>
php脚本:注意需要保存命名随意已经自动识别,我是命名为qq_fabiao.php,然后设置提交地址,cookie文件qq_cookie.txt需要填写抓包获取的空间登录cookie,以通过登录验证,qq_cookie.txt与php文件同目录.
提交参数说明:
$_POST['qq']---用户QQ
$_POST['g_tk']--这个参数很关键,获得这个参数,需要抓下发表时提交的post地址后面调用的g_tk=1276354485,POST http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=1276354485里的g_tk=1276354485
立即学习“PHP免费学习笔记(深入)”;
$_POST['title']---文章标题,不得空
发卡宝是一个专业的软件卡密等虚拟商品在线交易平台,拥有多种兑换方式,费率低,结算快,正规企业平台一直稳定运营,24小时不间断提供自动发卡服务。【模板说明】试用版自带一套模板(响应式)【环境支持】PHP环境 / 200M或以上空间大小 / 开启父路径 / 设置index.php为默认首页 / 目录写入权限需要开启【数据库】MySQL【安装步骤】将文件上传至空间目录,运行“http://域名/inst
$_POST['content']---文章内容,不得空
本文地址:
转载随意,但请附上文章地址:-)










