1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45, 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
<?php $discuz _url = ' http://www.jb51.net/';//Forum address $login _url = $discuz _url. ' Login.php?action=login ';//login 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 must be filled in $post _fields[' username '] = ' tianxin '; $post _fields[' password '] = ' 111111 '; Security Questions $post _fields[' questionid '] = 0; $post _fields[' answer '] = '; @todo Verification Code $post _fields[' seccodeverify '] = '; Gets 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 ('/<inputs*type= "hidden" s*name= "Formhash" s*value= "(. *?)" S*/>/i ', $contents, $matches); if (!empty ($matches)) {$formhash = $matches [1];} else {die (' not found the Forumhash. ');} //post data, get Cookie,cooki E files are placed in the temp directory of the Web site $cookie _file = Tempnam ('./temp ', ' cookies '); $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 can take a cookie file to simulate posting, FID for the forum's column ID $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); Here the hash code and the landing window of the hash code is not quite the same, here hidden an id attribute preg_match ('/<inputs*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[' subject '] = ' test2 '; Post content $post _data[' message '] = ' test2 '; $post _data[' topicsubmit '] = "yes"; $post _data[' extra '] = '; Post tags $post _data[' tags '] = ' test '; The hash code of the post, this very key! If this hash code is missing, Discuz willWarn you that the page is incorrect $post _data[' Formhash ']= $formhash; $ch = Curl_init ($send _url); curl_setopt ($ch, Curlopt_referer, $send _url); Camouflage 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); Clean cookie file unlink ($cookie _file);?> |