Simulate get POST request function /* Function Description: Function: Request way can get,post, can send the cookie, save the Cookiefile file Parameters: $url-----Request URL $referer---Source URL $postdata The data used for the POST request, ' is a GET request Cookies $cookie---------sent $cookiefile-----saved cookiefile File Return value: Returns 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 Source Address $header. = "Cookie:". $cookie; Set cookie, default null Request method get post, via $postdata empty---get, non-empty----post if ($postdata = = ") $method = ' GET '; else $method = ' POST '; Defines the array used to create the stream $opts =array (); $opts [' http ']=array (' method ' = ' $method, ' header ' = ' $header, ' content ' = ' $postdata '); Generate flow $context =stream_context_create ($opts); Send request, get source code $yuanma =file_get_contents ($url, False, $context); Whether you need to save the cookie to the file, $cookiefile not empty if ($cookiefile! = ") { Echo ' Need to save cookies '; Determine if the save file exists and does not exist create if (!file_exists ($cookiefile)) { File_put_contents ($cookiefile, "); } Get cookies and save them $response =implode ("RN", $http _response_header); Match cookies with regular matches $zengze = "/set-cookie: (. *?) Rn/"; Preg_match_all ($zengze, $response, $cookie _arr); There is a match, save if (!empty ($cookie _arr[1])) { $cookiestr =implode ('; ', $cookie _arr[1]); File_put_contents ($cookiefile, $COOKIESTR); Echo ' Successfully saved cookies '; } else echo ' does not match to cookie '; }//end if ($cookiefile! = ") Back to Source return $yuanma; }//end function Request ($url, $referer, $postdata, $cookie, $cookiefile) Get 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; }
Get the current file name $nowurl =getcururl (); Echo $nowurl;
form output, when not submitted if (!isset ($_post[' QQ ')) { Echo '; Die (); } /* Submit parameter Description: $_post[' QQ ']---user qq $_post[' G_TK ']--This parameter is key, to get this parameter, need to grasp the post address submitted at the time of the call after the g_tk=1276354485, g_tk=1276354485 in the http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=1276354485 of the road post $_post[' title '---article title, not empty $_post[' content '---articles, not empty */
Header (' content-type:text/html;charset=gb2312 '); Set_time_limit (0); Ob_end_clean (); Ob_start (); Gets the cookie file, does not exist, and exits the program $cookiefile =dirname (__file__). ' Qq_cookie.txt '; if (!file_exists ($cookiefile)) { Echo ' Qq_cookie.txt does not exist, automatically created, please fill in the Packet capture cookie '; File_put_contents ($cookiefile, "); Die (' program exit '); } exist, read cookies else{ $cookie =file_get_contents ($cookiefile);//Login Cookie $cookie =urlencode ($cookie); } Echo ' Cookie: '. $cookie. ' '; Important information that forms the publication page, post data, etc. QQ number if (Empty ($_post[' QQ ')) | | Preg_match ('/[^0-9]/is ', $_post[' qq ')) Die (' QQ number is wrong, must be number '); else $qq =$_post[' QQ '];//QQ No. if (Empty ($_post[' g_tk ')) | | Preg_match ('/[^0-9]/is ', $_post[' g_tk ')) Die (' POST important parameter g_tk not valid, must be number, please use the value of the grab packet '); $g _tk=$_post[' G_TK ']; $title =empty ($_post[' title ')? Die (' Caption Not empty '): $_post[' title '];//article title $content =empty ($_post[' content ')? Die (' Contents not empty '): $_post[' content '];//contents $category = ' personal diary ';//classification $fabiao = ' http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk= '. $g _tk;//Publishing Processing page $referer = ' http://ctc.qzs.qq.com/qzone/v5/toolpages/fp_gbk.html ';//source page $r 1= ' 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 ('. $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 data $postdata =urlencode ($postdata); Echo $postdata; Send request, get source code $yuanma =request ($fabiao, $r 1, $postdata, $cookie, '); if (Strpos ($yuanma, ' success of publication ')) echo $title. ' Post success '; else Echo ' Publish failed: Right click on the source code, you can see the specific error '. $yuanma; ?>
PHP Script: Note the need to save the name arbitrarily has been automatically recognized, I was named qq_fabiao.php, and then set the submission address, cookie file qq_cookie.txt need to fill in the capture packet to get the space login cookie to pass login authentication, qq_ Cookie.txt the same directory as the PHP file
/* Submit parameter Description: $_post[' QQ ']---user qq $_post[' G_TK ']--This parameter is key, to get this parameter, need to grasp the post address submitted at the time of the call after the g_tk=1276354485, g_tk=1276354485 in the http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=1276354485 of the road post
$_post[' title '---article title, not empty $_post[' content '---articles, not empty |