Table of Contents
php模拟用户自动在qq空间发表文章的方法,
Home php教程 php手册 php模拟用户自动在qq空间发表文章的方法,

php模拟用户自动在qq空间发表文章的方法,

Jun 13, 2016 am 09:17 AM
php method simulation

php模拟用户自动在qq空间发表文章的方法,

本文实例讲述了php模拟用户自动在qq空间发表文章的方法。分享给大家供大家参考。具体分析如下:

我们这里是一个简单的利用php来模拟登录后再到QQ空间发送文章的一个简单的程序,有需要的朋友可以参考,或改进可以给我意见,代码如下:

复制代码 代码如下:

//模拟get post请求函数
/*
函数说明:
功能:请求方式可以get,post,可以发送的cookie,保存的cookiefile文件
参数:$url-----请求url    $referer---来源url    $postdata----------用于post请求的数据,''为get请求
$cookie---------发送的cookie     $cookiefile-----保存的cookiefile文件
返回值:返回获取的源码
*/
function request($url,$referer='',$postdata='',$cookie='',$cookiefile=''){
//header设置
$header='';
$header.="Content-Type: application/x-www-form-urlencodedrn";//内容请求类型
$header.="User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)rn";//浏览器字段
$header.="Referer:".$referer."rn";//设置来源地址
$header .= "Cookie:".$cookie ; //设置cookie,默认空
//请求方法get post,通过$postdata空---get,非空----post
if($postdata=='')$method='GET';
else $method='POST';
//定义用于创建流的数组
$opts=array();
$opts['http']=array('method'=>$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 '


qq号码:

g_tk:

标题:

内容:


';
die();
}
 
/*
提交参数说明:
$_POST['qq']---用户QQ
$_POST['g_tk']--这个参数很关键,获得这个参数,需要抓下发表时提交的post地址后面调用的g_tk=123456789,
路POST http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789里的g_tk=123456789
$_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('
'.$content.'
').'&tweetflag=0&cb_autograph=1&topflag=0&needfeed=0&g_tk='.$g_tk.'&_fp_refer=http%3A%2F%2Fctc.qzs.qq.com%2Fqzone%2Fnewblog%2Fv5%2Feditor.html%3Fsource%3D1%7Chttp%3A%2F%2Fctc.qzs.qq.com%2Fqzone%2Fnewblog%2Fv5%2Feditor.html%3Fsource%3D1%3Chttp%3A%2F%2Fuser.qzone.qq.com%2F'.$qq.'%2Fmain';//post数据
//$postdata=urlencode($postdata);
//echo $postdata;
//发送请求,获取源码
$yuanma=request($fabiao,$r1,$postdata,$cookie,'');
if(strpos($yuanma,'发表成功'))echo $title.'  发表成功
';
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=123456789,POST http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789里的g_tk=123456789

$_POST['title']---文章标题,不得空

$_POST['content']---文章内容,不得空

希望本文所述对大家的php程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles