


PHP simulates the method for users to automatically publish articles in QQ space, _PHP tutorial
php simulates the method for users to automatically publish articles in qq space,
The example in this article describes how PHP simulates users to automatically publish articles in QQ space. Share it with everyone for your reference. The specific analysis is as follows:
What we have here is a simple program that uses PHP to simulate logging in and then sending articles to QQ space. Friends in need can refer to it or give me suggestions for improvement. The code is as follows:
/*
Function description:
Function: The request method can be get, post, cookies that can be sent, and cookie files saved
Parameters: $url-----request url $referer---source url $postdata----------data for post request, '' is for get request
$cookie-----sent cookie $cookiefile-----saved cookiefile
Return value: Return the obtained source code
*/
function request($url,$referer='',$postdata='',$cookie='',$cookiefile=''){
//header settings
$header='';
$header.="Content-Type: application/x-www-form-urlencodedrn";//Content request type
Media Center PC 6.0)rn";//Browser field
$header.="Referer:".$referer."rn";//Set the source address
$header .= "Cookie:".$cookie; //Set cookie, empty by default
//Request method get post, pass $postdata empty---get, non-empty----post
if($postdata=='')$method='GET';
else $method='POST';
//Define the array used to create the stream
$opts=array();
$opts['http']=array('method'=>$method,'header'=>$header,'content'=>$postdata);
//Generate stream
$context=stream_context_create($opts);
//Send a request and get the source code
$yuanma=file_get_contents($url,false,$context);
//Whether it is necessary to save cookies to a file, when $cookiefile is not empty
if($cookiefile!=''){
echo 'Need to save cookies
';
//Judge whether the saved file exists or create it if it does not exist
if(!file_exists($cookiefile)){
file_put_contents($cookiefile,'');
}
//Get the cookie and save it
$response=implode("rn",$http_response_header);
//Use regular expressions to match cookies
$zengze="/Set-Cookie:(.*?)rn/";
preg_match_all($zengze,$response,$cookie_arr);
//There is a match, save
if(!emptyempty($cookie_arr[1])){
$cookiestr=implode(';',$cookie_arr[1]);
file_put_contents($cookiefile,$cookiestr);
echo 'Save cookie successfully
';
}
else echo 'No cookie matched
';
}//end if($cookiefile!='')
//Return to source code
return $yuanma;
}//end function request($url,$referer,$postdata,$cookie,$cookiefile)
//Get the current script URL
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;
}
//Get the current file name
$nowurl=GetCurUrl();
//echo $nowurl;
//Form output, when not submitted
if(!isset($_POST['qq'])){
echo '';
die();
}
/*
Submission parameter description:
$_POST['qq']---User QQ
$_POST['g_tk']--This parameter is very critical. To obtain this parameter, you need to grab the g_tk=123456789 called after the post address submitted when publishing,
POST http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789 g_tk=123456789
$_POST['title']---Article title, must not be empty
$_POST['content']---Article content, must not be empty
*/
header('Content-Type:text/html;charset=gb2312');
set_time_limit(0);
//ob_end_clean();
//ob_start();
//Get the cookie file, if it does not exist, exit the program
$cookiefile=dirname(__FILE__).'qq_cookie.txt';
if(!file_exists($cookiefile)){
echo 'qq_cookie.txt does not exist, it will be created automatically, please fill in the captured cookie
';
file_put_contents($cookiefile,'');
die('Program exit');
}
//Exists, read cookie
else{
$cookie=file_get_contents($cookiefile);//Login cookie
//$cookie=urlencode($cookie);
}
//echo 'cookie:'.$cookie.'
';
//Important information that constitutes the publication page, post data, etc.
//qq number
if(emptyempty($_POST['qq'])||preg_match('/[^0-9]/is',$_POST['qq']))die('The qq number is wrong, it must be digits');
else $qq=$_POST['qq'];//qq number
if(emptyempty($_POST['g_tk'])||preg_match('/[^0-9]/is',$_POST['g_tk']))die('post important parameter g_tk is illegal and must be a number, Please use the value of the captured packet');
$g_tk=$_POST['g_tk'];
$title=emptyempty($_POST['title'])?die('Title cannot be empty'):$_POST['title'];//Article title
$content=emptyempty($_POST['content'])?die('Content cannot be empty'):$_POST['content'];//Content
$category='Personal Diary';//Category
$fabiao='http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk='.$g_tk;//Posting processing page
$referer='http://ctc.qzs.qq.com/qzone/v5/toolpages/fp_gbk.html';//Source page
$r1='http://user.qzone.qq.com/'.$qq.'/infocenter';//List access source page
$postdata='uin='.$qq.'&category='.urlencode($category).'&title='.urlencode($title).'&content='.urlencode($content).'&html='.urlencode ('
//$postdata=urlencode($postdata);
//echo $postdata;
//Send a request and get the source code
$yuanma=request($fabiao,$r1,$postdata,$cookie,'');
if(strpos($yuanma,'Published successfully'))echo $title.' Published successfully
';
else echo 'Failed to publish: right-click to view the source code and you can see the specific errors'.$yuanma;
?>
php script:Note that you need to save the name and it will be automatically recognized. I named it qq_fabiao.php, and then set the submission address. The cookie file qq_cookie.txt needs to fill in the space login cookie obtained by the packet capture to pass the login verification. ,qq_cookie.txt is in the same directory as the php file.
Submission parameter description:
$_POST['qq']---User QQ
$_POST['g_tk']--This parameter is very critical. To obtain this parameter, you need to grab the g_tk=123456789 called after the post address submitted when publishing, POST http://b1.qzone.qq.com/ g_tk=123456789 in cgi-bin/blognew/blog_add?g_tk=123456789
$_POST['title']---Article title, must not be empty
$_POST['content']---Article content, must not be empty
I hope this article will be helpful to everyone’s PHP programming design.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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

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,

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.

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

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 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.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.
