<? 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. $ Cookiefile = 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 |