|
$ Discuz_url = 'http: // localhost/klive/root/Discuz_X2.5_ SC _GBK/'; // forum address
$ Login_url = $ discuz_url. 'member. php? Mod = logging & action = login '; // logon page address
$ Post_fields = array ();
// The following two items do not need to be modified
$ Post_fields ['loginfield'] = 'username ';
$ Post_fields ['loginsubmit '] = 'true ';
// Username and password, required
$ Post_fields ['username'] = 'admin ';
$ Post_fields ['password'] = 'admin ';
// Security question
$ Post_fields ['questionid'] = 0;
$ Post_fields ['answer'] = ";
// @ Todo verification code
$ Post_fields ['seccodeverify '] = ";
// Obtain the FORMHASH form
$ 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. the cookie file is stored in the temp directory of the website.
$ Cookie_file = tempnam ('./temp', 'cooker ');
$ 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_COOKIEJAR, $ cookie_file );
Curl_exec ($ ch );
Curl_close ($ ch );
// Take the key cookie file to simulate post with the cookie file. fid is the topic ID of the Forum.
$ Send_url = $ discuz_url. "forum. php? Mod = post & 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. the hidden here 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 Post hash code, which 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, CURLOPT_RETURNTRANSFER, 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 );
Curl_close ($ ch );
// Clear cookie files
Unlink ($ cookie_file );
?> |