Php simulates login to the DZ Forum through curl. phpcurldz Forum _ PHP Tutorial

Source: Internet
Author: User
Php simulates login to DZ Forum and phpcurldz Forum through curl. Php simulates login to the DZ Forum through curl. libcurl of the phpcurldz Forum also supports HTTPS authentication, HTTPPOST, HTTPPUT, and FTP upload (this can also be completed through php ftp extension) HTTP simulates login to DZ Forum through curl based on form php, phpcurldz Forum

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 $ discuz_url = 'http: // www.bkjia.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 ('/
 /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, the hidden has an id attribute preg_match ('/
 /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);?>

The above is all the content of this article. I hope you will like it.

Libcurl also supports HTTPS authentication, http post, http put, FTP upload (this can also be completed through the FTP extension of PHP), HTTP based on forms...

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.