We here is a simple use of PHP to simulate login and then to the QQ space to send an article of a simple program, there is a need for friends can refer to, or improve can give me comments, code as follows:
$method, ' header ' = ' $header, ' content ' and ' $postdata '); Generate Stream $context =stream_context_create ($opts); Send a request to get the 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 ' needs to save the cookie
'; Determine if the save file exists and does not exist create if (!file_exists ($cookiefile)) {file_put_contents ($cookiefile, ')}//Get cookie, save $response = Implode ("RN", $http _response_header); Match Cookie with regular $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 ' Successfully saved cookies
'; } else echo ' does not match to cookie
'; }//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 (!emptyempt Y ($_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, without commit if (!isset ($_post[' qq ")) {echo '; Die ();} /* Submit parameter Description: $_post[' QQ ']---user qq $_post[' G_TK ']--This parameter is key, get this parameter, need to catch the post address submitted at the time of the g_tk=123456789, the Road Post http:// b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789 g_tk=123456789 $_post[' title ']---article title, not empty $_POST[' Content ']---article contents, 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 for creation, 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 cookie for the packet capture
'; File_put_contents ($cookiefile, "); Die (' program exit '); }//exists, reads the cookie else{$cookie =file_get_contents ($cookiefile);//Login cookie//$cookie =urlencode ($cookie);}//echo ' Cookies: '. $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 (' QQ number is wrong, must be number '); else $qq =$_post[' QQ '];//QQ if (emptyempty ($_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 =emptyempty ($_post[' title ')? Die (' Caption Not empty '): $_post[' title '];//article title $content =emptyempty ($_post[' content '])? Die (' content not empty '): $_post[' content '];//contents $category = ' personal diary ';//Category $fabiao = ' Http://b1.qzone.qq.com/cgi-bin/blognew/blog_ Add?g_tk= '. $g _tk;//Publish 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 a request for source code $yuanma =request ($fabiao, $r 1, $postdata, $cookie, '); if (Strpos ($yuanma, ' publish Success ')) echo $title. ' Publishing success
'; else Echo ' Publish failed: Right click on the source code, you can see the specific error '. $yuanma;?>
Code for reference only, the success rate to be verified, there is a problem can be answered in this blog or message: http://www.lai18.com/content/368902.html