|
<? Php
// Simulate the get post request Function
/*
Function Description:
Function: The request method can be get, post, cookie that can be sent, and saved cookiefile.
Parameter: $ url ----- request url $ referer --- source url $ postdata ---------- used for post request data, ''is a 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
$ 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 "; // browser Field
$ Header. = "Referer:". $ referer. "rn"; // set the source address
$ Header. = "Cookie:". $ cookie; // sets the cookie. The default value is null.
// Request Method get post, with $ postdata null --- get, non-null ---- post
If ($ postdata = '') $ method = 'get ';
Else $ method = 'post ';
// Define the array used to create a stream
$ Opts = array ();
$ Opts ['http'] = array ('method' => $ method, 'header' => $ header, 'content' => $ postdata );
// Generate a stream
$ Context = stream_context_create ($ opts );
// Send a request to obtain the source code
$ Yuanma = file_get_contents ($ url, false, $ context );
// Whether to save the cookie to the file. $ when cookiefile is not empty
If ($ cookiefile! = ''){
Echo 'cookie needs to be saved <br> ';
// Determine whether the saved file exists and does not exist
If (! File_exists ($ cookiefile )){
File_put_contents ($ cookiefile ,'');
}
// Obtain and save the cookie
$ Response = implode ("rn", $ http_response_header );
// Use the regular expression to match the cookie
$ Zengze = "/Set-Cookie :(.*?) Rn /";
Preg_match_all ($ zengze, $ response, $ cookie_arr );
// Match exists and save
If (! Empty ($ cookie_arr [1]) {
$ Cookiestr = implode (';', $ cookie_arr [1]);
File_put_contents ($ cookiefile, $ cookiestr );
Echo 'successfully saved the cookie <br> ';
}
Else echo 'the cookie does not match <br> ';
} // End if ($ cookiefile! = '')
// Return the source code
Return $ yuanma;
} // End function request ($ url, $ referer, $ postdata, $ cookie, $ cookiefile)
// Obtain the current Script URL
Function GetCurUrl ()
{
If (! Empty ($ _ SERVER ["REQUEST_URI"])
{
$ ScriptName = $ _ SERVER ["REQUEST_URI"];
$ Nowurl = $ scriptName;
}
Else
{
$ ScriptName = $ _ SERVER ["PHP_SELF"];
If (empty ($ _ SERVER ["QUERY_STRING"])
{
$ Nowurl = $ scriptName;
}
Else
{
$ Nowurl = $ scriptName ."? ". $ _ SERVER [" QUERY_STRING "];
}
}
Return $ nowurl;
}
// Obtain the current file name
$ Nowurl = GetCurUrl ();
// Echo $ nowurl;
// Form output, no submission
If (! Isset ($ _ POST ['qq']) {
Echo '<form method = "post" action = "'. $ nowurl. '">
Qq number: <input type = "text" name = "qq"> <br>
G_tk: <input type = "text" name = "g_tk"> <br>
Title: <input type = "text" name = "title"> <br>
Content: <input type = "text" name = "content"> <br>
<Input type = "submit" value = "Post">
</Form> ';
Die ();
}
/*
Description of submitted parameters:
$ _ POST ['qq'] --- user qq
$ _ POST ['G _ tk '] -- this parameter is critical. To obtain this parameter, You need to capture the g_tk = 1276354485,
Road POST http://b1.qzone.qq.com/cgi-bin/blognew/blog_add? G_tk = 1276354485 in 1276354485
$ _ POST ['title'] --- Article title, which cannot be blank
$ _ POST ['content'] --- content of the article, which cannot be blank
*/
Header ('content-Type: text/html; charset = gb2312 ');
Set_time_limit (0 );
// Ob_end_clean ();
// Ob_start ();
// Obtain the cookie file. It does not exist and exits the program.
Using cookiefile1_dirname({file=}.'qq_cookie.txt ';
If (! File_exists ($ cookiefile )){
Echo 'qq_cookie.txt does not exist. It is automatically created. Please fill in the cookie for packet capture <br> ';
File_put_contents ($ cookiefile ,'');
Die ('program exited ');
}
// Exist, read cookie
Else {
$ Cookie = file_get_contents ($ cookiefile); // logon cookie
// $ Cookie = urlencode ($ cookie );
}
// Echo 'cookie: '. $ cookie.' <br> ';
// Make up important information such as posting pages and post data
// QQ number
If (empty ($ _ POST ['qq']) | preg_match ('/[^ 0-9]/is', $ _ POST ['qq']) die ('qq number is incorrect, it must be number ');
Else $ qq =$ _ POST ['qq']; // qq number
If (empty ($ _ POST ['G _ tk ']) | preg_match ('/[^ 0-9]/is ', $ _ POST ['G _ tk ']) die ('Post's important parameter g_tk is invalid and must be a number. Use the value of the captured package ');
$ G_tk = $ _ POST ['G _ tk '];
$ Title = empty ($ _ POST ['title'])? Die ('title cannot be blank '): $ _ POST ['title']; // article title
$ Content = empty ($ _ POST ['content'])? Die ('content not null'): $ _ POST ['content']; // content
$ Category = 'personal diaries '; // category
$ Fabiao = 'HTTP: // b1.qzone.qq.com/cgi-bin/blognew/blog_add? G_tk = '. $ g_tk; // post a processing page
$ Referer = 'HTTP: // ctc.qzs.qq.com/qzone/v5/toolpages/fp_gbk.html'#//#page
$ R1 = 'HTTP: // user.qzone.qq.com/'.{qq.'/infocenter'#//{ page
$ Postdata = 'uin = '. $ qq. '& category = '. urlencode ($ category ). '& title = ". urlencode ($ title ). "& content = '. urlencode ($ content ). '& html = '. urlencode ('<div class = "blog_details_20151120"> '. $ content. '</div> sources % 3 Fsource % 3D1% 3 Chttp % 3A % 2F % 2Fuser.qzone.qq.com % 2F '. $ qq. '% 2fmain'; // post Data
// $ Postdata = urlencode ($ postdata );
// Echo $ postdata;
// Send a request to obtain the source code
$ Yuanma = request ($ fabiao, $ r1, $ postdata, $ cookie ,'');
If (strpos ($ yuanma, 'Post succeeded ') echo $ title. 'Post succeeded <br> ';
Else echo 'posting failed: Right-click to view the source code and you will see the specific error '. $ yuanma;
?>
Php script: the same directory as the php File
/*
Description of submitted parameters:
$ _ POST ['qq'] --- user qq
$ _ POST ['G _ tk '] -- this parameter is critical. To obtain this parameter, You need to capture the g_tk = 1276354485,
Road POST http://b1.qzone.qq.com/cgi-bin/blognew/blog_add? G_tk = 1276354485 in 1276354485
$ _ POST ['title'] --- Article title, which cannot be blank
$ _ POST ['content'] --- content of the article, which cannot be blank |