DiscuzX2.5PHP login publishing module

Source: Internet
Author: User
DiscuzX2.5PHP login publishing module

Class class_dz.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 /** @ Author 80aj * @ email a@80aj.com * @ descripton: author: big waterwheel, achieve discuz2.5 login Post * @ filename class_dz.php */classdiscuz_post {constLOGIN_PROGRAM = 'member. php? Mod = logging & action = login & loginsubmit = yes & infloat = yes '; constPOST_PROGRAM = 'forum. php? Mod = post & action = newthread & fid = '; private $ host; private $ cookie_file;/***** @ param unknown $ host */publicfunction _ construct ($ host) {$ this-> host = $ host;}/***** @ return unknown */publicfunctionget_formhash () {$ login_url = $ this-> _ get_Login_Url (); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ login_url); curl_setopt ($ ch, CURLOPT_HEADER, false); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true ); $ contents = curl_exec ($ ch); curl_close ($ ch); preg_match ('//IsU ', $ contents, $ matches); if (! Empty ($ matches) {$ formhash = $ matches [1];} else {// die ('Not found the forumhash. ');} return $ formhash;}/***** @ param unknown $ post * @ return string */publicfunctionlogin ($ user, $ pass) {$ login_info = array ('username' => $ user, 'password' => $ pass, 'referer' => $ this-> host, 'questionid' => 0, 'answer' => '', 'seccodeverify '=>'', 'formhash' => $ this-> get_formhash ()); $ login_url = $ this-> _ get_Login_Url (); $ cookie_file = tempnam ('. /temp ', 'cookier'); $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_HEADER, false); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ($ ch, CURLOPT_POST, true); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ login_info); curl_setopt ($ ch, interval, $ cookie_file); curl_exec ($ ch ); curl_close ($ ch); $ this-> cookie_file = $ cookie_file; return $ cookie_file ;} /***** @ param unknown $ fid * @ return string */publicfunctionuse_cookie ($ fid) {$ send_url = $ this-> _ get_Post_Url ($ fid ); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ send_url); curl_setopt ($ ch, CURLOPT_HEADER, false); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ this-> cookie_file); $ contents = curl_exec ($ ch); curl_close ($ ch); preg_match_all ('//IsU ', $ contents, $ matches); if (! Empty ($ matches) {$ formhash = $ matches [1] [0];} else {$ formhash = '';} return $ formhash ;} /***** @ param unknown $ fid * @ param unknown $ thread_data */publicfunctionpost_newthread ($ fid, $ title, $ content, $ tags) {$ thread_data = array ('subobject' => $ title, 'message' => $ content, 'topicsubmit '=> "yes", 'Extra' => '', 'tags' => $ tags, 'formhash' => $ this-> use_cookie ($ fid); $ send_url = $ this-> _ get_Post_Url ($ fid ); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ send_url); curl_setopt ($ ch, CURLOPT_REFERER, $ send_url); curl_setopt ($ ch, CURLOPT_HEADER, false ); curl_setopt ($ ch, success, true); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ this-> cookie_file); curl_setopt ($ ch, CURLOPT_POST, true); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ thread_data); $ contents = curl_exec ($ ch); curl_close ($ ch); return ;} /***** @ param unknown $ fid * @ return string */privatefunction_get_Post_Url ($ fid) {return $ this-> host. self: POST_PROGRAM. intval ($ fid);}/***** @ return string */privatefunction_get_Login_Url () {return $ this-> host. self: LOGIN_PROGRAM ;}}

Test implementation class

12345678910111213 Include_once 'class _ dz. php '; $ host = "http: // localhost/dz/"; // server address $ fid = 2; // Plate ID $ user = "admin "; // username $ pass = "admin"; // user password $ title = "Let's take a look at it together"; // title $ content = "must be a pretty girl before sending it, you said "no"; // Body $ tags = "long live beauty, oh yeah"; // tags $ rc = newdiscuz_post ($ host); $ rc-> login ($ user, $ pass); $ rc-> post_newthread ($ fid, $ title, $ content, $ tags );

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.