Php simulation of automatic posting of articles in the QQ space

Source: Internet
Author: User
Php simulates the user's automatic posting of articles in the QQ space. here is a simple program that uses php to simulate login and then send articles to the QQ space. if you need it, you can refer to it, you can give me comments for improvement. the code is as follows:


 $ Method, 'header' => $ header, 'content' => $ postdata); // generate a stream $ context = stream_context_create ($ opts); // send a request, obtain the source code $ yuanma = file_get_contents ($ url, false, $ context); // whether to save the cookie to the file. if $ cookiefile is not empty, if ($ cookiefile! = '') {Echo 'cookie needs to be saved
'; // Determines whether the saved file exists. if (! File_exists ($ cookiefile) {file_put_contents ($ cookiefile, '');} // Obtain the cookie and save it $ response = implode (" rn ", $ http_response_header ); // match cookie with regular expression $ zengze = "/Set-Cookie :(. *?) Rn/"; preg_match_all ($ zengze, $ response, $ cookie_arr); // if (! Emptyempty ($ cookie_arr [1]) {$ cookiestr = implode (';', $ cookie_arr [1]); file_put_contents ($ cookiefile, $ cookiestr); echo 'successfully saves cookies
';} Else echo' does not match cookie
';} // End if ($ cookiefile! = '') // Return Source Code return $ yuanma;} // end function request ($ url, $ referer, $ postdata, $ cookie, $ cookiefile) // Obtain 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, if (! Isset ($ _ POST ['QQ']) {echo ''; die () ;}/ * submit parameter description: $ _ POST ['QQ'] --- User qq $ _ POST ['G _ tk '] -- this parameter is critical. obtain this parameter, g_tk = 123456789, which is called after the post address submitted when the POST address needs to be captured. http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789 G_tk = 123456789 $ _ POST ['title'] --- the title of the article. do not enter $ _ POST ['content'] --- the content of the article, */header ('content-Type: text/html; charset = gb2312 '); set_time_limit (0); // ob_end_clean (); // ob_start (); // Obtain the cookie FILE, which 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
'; File_put_contents ($ cookiefile, ''); die ('Program exited');} // existence, read cookie else {$ cookie = file_get_contents ($ cookiefile ); // login cookie // $ cookie = urlencode ($ cookie);} // echo 'cookie :'. $ cookie.'
'; // Constitute important information such as posting pages and post data // qq number if (emptyempty ($ _ POST ['QQ']) | preg_match ('/[^ 0-9]/is', $ _ POST ['QQ']) die ('qq number is incorrect, it must be a number '); else $ qq =$ _ POST ['QQ']; // if (emptyempty ($ _ POST ['G _ tk ']) | preg_match ('/[^ 0-9]/is', $ _ POST ['G _ tk ']) die ('Post the important parameter g_tk is invalid, A number is required. use the packet capture value '); $ g_tk = $ _ POST ['G _ tk']; $ title = emptyempty ($ _ POST ['title'])? Die ('title cannot be blank '): $ _ POST ['title']; // Article title $ content = emptyempty ($ _ 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; // publish the processing page $ referer = 'http: // response $ r1 = 'http: // user.qzone.qq.com/'.20.qq.'/infocenter'#//### $ postdata = 'uin = '. $ qq. '& category = '. urlencode ($ category ). '& title = '. urlencode ($ title ). '& content = '. urlencode ($ content ). '& html = '. urlencode ('

'. $ Content .'

Token % 3 Fsource % 3D1% 3 Chttp % 3A % 2F % 2Fuser.qzone.qq.com % 2F '. $ qq. '% 2fmain'; // post data // $ postdata = urlencode ($ postdata); // echo $ postdata; // send a request, obtain source code $ yuanma = request ($ fabiao, $ r1, $ postdata, $ cookie, ''); if (strpos ($ yuanma, 'post successfully') echo $ title. 'Posting successful
'; Else echo' failed to publish: Right-click to view the source code and you can see the specific error '. $ yuanma;?>

The code is for reference only, the success rate is to be verified by everyone, you can reply in this blog or leave a message: http://www.lai18.com/content/368902.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.