Php simulates the implementation code of logging on to the discuz Forum through curl, curldiscuz
Libcurl also supports HTTPS authentication, http post, http put, and FTP upload (this can also be completed through the FTP extension of PHP) HTTP form-based upload, proxy, cookies, user name + password authentication.
Php curl is really quite easy to use. articles related to searching on the Internet are about simulated curl login. Few people provide source code for simulating discuz posts.
<? Php $ discuz_url = 'HTTP: // www.lai18.com/'#//forum address $ login_url = $ discuz_url. 'login. php? Action = login '; // logon page address $ post_fields = array (); // you do not need to modify the following two items: $ post_fields ['loginfield'] = 'username '; $ post_fields ['loginsubmit '] = 'true'; // username and password, which must be set to $ post_fields ['username'] = 'tiance '; $ post_fields ['Password'] = '000000'; // security question $ post_fields ['questionid'] = 0; $ post_fields ['ancer'] = ''; // @ todo Verification Code $ post_fields ['seccodeverify '] = ''; // obtain the form FORMHASH $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); $ contents = curl_exec ($ ch); curl_close ($ ch ); preg_match ('/<input \ s * type = "hidden" \ s * name = "formhash" \ s * value = "(. *?) "\ S * \/>/I ', $ contents, $ matches); if (! Empty ($ matches) {$ formhash = $ matches [1];} else {die ('Not found the forumhash. ');} // POST the data to obtain the COOKIE. Put the cookie file in the temp directory of the website $ cookie_file = tempnam ('. /temp ', 'cookier'); $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, CURLOPT_COOKIEJA R, $ cookie_file); curl_exec ($ ch); curl_close ($ ch); // The Key cookie file can be taken to simulate post with the cookie file, fid is the topic ID of the forum $ send_url = $ discuz_url. "post. php? Action = newthread & fid = 2 "; $ ch = curl_init ($ send_url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file); $ contents = curl_exec ($ ch); curl_close ($ ch ); // The hash code here is not the same as the hash code in the login window, here, hidden has an id attribute preg_match ('/<input \ s * type = "hidden" \ s * name = "formhash" \ s * id = "formhash" \ s * value = "(. *?) "\ S * \/>/I ', $ contents, $ matches); if (! Empty ($ matches) {$ formhash = $ matches [1];} else {die ('Not found the forumhash. ') ;}$ post_data = array (); // post title $ post_data ['subobject'] = 'test2 '; // post content $ post_data ['message'] = 'test2'; $ post_data ['topicsubmit '] = "yes"; $ post_data ['extra'] = ''; // post tag $ post_data ['tags'] = 'test'; // The hash code of the post. This is critical! If this hash code is missing, discuz will warn you of incorrect webpage. $ post_data ['formhash'] = $ formhash; $ ch = curl_init ($ send_url); curl_setopt ($ ch, CURLOPT_REFERER, $ send_url); // disguise REFERER curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, expires, 0); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_data); $ contents = curl_exec ($ ch); cur Rochelle close ($ ch); // clear the cookie file unlink ($ cookie_file);?>
CURL technical knowledge tutorial series technical tutorials
Http://blog.csdn.net/hello_katty/article/details/45557423