本帖最后由 huamaolin 于 2009-11-12 13:31:38 编辑

解决方案 »

  1.   

     <?php
     
     
     
     
     
     //初始化
      $tread = array(  'root' => 'http://www.ly5s.com/bbs/index.php',  'login'=> 'logging.php?action=login',  'username'=>'烈焰灬林',  'password'=>'273319572',  'link'=>'http://www.ly5s.com/bbs/post.php?action=newthread&fid=13&extra=page%3D1', //这个地址可以在你要发帖的板块点击发帖,则地址栏的地址就是  'typeid'=>0, //有的板块需要typeid  'subject'=>'发帖标题',  'content'=>'发帖内容',);
      $tread['login'] = $tread['root'] . $tread['login'];
      
      //进行登陆
      
      $cookie_jar = tempnam('./tmp','cookie');//获取登陆后的cookie
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $tread['login']);        //打开地址,获取随机hash码   
      ob_start();   
      curl_exec($ch);   
      $content = ob_get_contents();   
      ob_end_clean();   
      curl_close($ch);
      $ch = curl_init();   
      $preg_1 = '/<input type="hidden" name="formhash" value="(.*?)" \/>/';   
      preg_match($preg_1, $content, $arr_match);   
      $hash = $arr_match['1'];        //隐藏传递的hash字符串;
      
      $request = "username={$tread[username]}&password={$tread[password]}&formhash={$hash}&loginsubmit=提交";
      curl_setopt($ch, CURLOPT_URL, $tread['login']);            //设置需要提交的url地址   
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    //设置为字符串方式   
        
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);     //存储cookie(文件要设置为777)   
      curl_setopt($ch, CURLOPT_HEADER, false);        //禁止头部信息   
      curl_setopt($ch, CURLOPT_NOBODY,true);          //显示页面内容   
      curl_setopt($ch, CURLOPT_POST, true);           //POST方式   
      curl_setopt($ch, CURLOPT_POSTFIELDS, $request);    //POST数据   
      //curl_setopt($ch, CURLOPT_REFERFER, $referer);       //伪装REFERER   
      curl_exec($ch);   
      curl_close($ch);   
      
      
      $ch = curl_init();   
      
      curl_setopt($ch, CURLOPT_URL, $tread['link']);        //打开地址,获取随机hash码   
      ob_start();   
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);     //存储cookie(文件要设置为777)   
      curl_exec($ch);   
      $content = ob_get_contents(); 
      ob_end_clean();  
      $preg_1 = '/<input type="hidden" name="formhash" id="formhash" value="(.*?)" \/>/';   
      //$preg_1 = '/<input type="hidden" name="formhash" value="(.*?)" \/>/';   
      preg_match($preg_1, $content, $arr_match);   
      $hash = $arr_match['1'];        //隐藏传递的hash字符串;
      
      $referer = $tread['link'];
      $tread['link'] .= "&formhash={$hash}";
      $request = "subject={$tread['subject']}&message={$tread['content']}&typeid={$tread[typeid]}&topicsubmit=yes&replysubmit=yes";
      curl_setopt($ch, CURLOPT_URL, $tread['link']);            //设置需要提交的url地址   
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);     //存储cookie(文件要设置为777)   
      curl_setopt($ch, CURLOPT_HEADER, false);        //禁止头部信息   
      curl_setopt($ch, CURLOPT_NOBODY,true);          //显示页面内容   
      curl_setopt($ch, CURLOPT_POST, true);           //POST方式   
      curl_setopt($ch, CURLOPT_POSTFIELDS, $request);    //POST数据   
      curl_setopt($ch, CURLOPT_REFERER, $referer);       //伪装REFERER   
      curl_exec($ch);   
      curl_close($ch);   
      
      
     }
     
    ?>
    有错误啊
      

  2.   

    没有弄明白你发贴的意图, 你要用DISCUZ7.0做吗?有什么需求呢?
      

  3.   

    <?php
    include 'Snoopy.class.php';
    include 'page.php';
      set_time_limit(0);
    class curl
    {
    var $cookiePath = '';
    var $loginUrl = '';
    var $data = array();//data
    var $destUrl = '';//dest url
    public $sourceUrlContents = '';
    protected $destUrlContents = '';
    protected $referer;//source url
    protected $postData = '';//post data
    protected $domain;//domain
    function __construct()
    {
       $this->cookiePath = tempnam('./tmp','cookie');
    }function joinData()
    {
       $postData = array();
       if(is_array($this->data) || sizeof(get_object_vars($this->data)) > 0)
       {
        foreach ($this->data as $i => $v)
        {
         $v = urlencode($v);
         $postData []= "{$i}={$v}";
        }
       }
       if(is_array($postData))
       {
        $this->postData = join('&', $postData);
       }
    }
    //set referer
    function setReferer($referer = '')
    {
       if($referer == '')
       {
        $this->referer = $this->domain;
       }else{
        $this->referer = $referer;
       }
    }
    //set dest url
    function setDestUrl($url = '')
    {
       if($url == '')
       {
        $this->destUrl = $this->domain;
       }else{
        $this->destUrl = $url;
       }
    }
    //get hidden contents
    function getHidden($fileds = 'formhash')
    {
       $contents = @file_get_contents($this->loginUrl);
       if($contents)
       {
        $exp_match = "/<input type=\"hidden\" name=\"formhash\" value=\"(.*)\" \/>/";
        preg_match_all($exp_match, $contents, $match);
        return ($match[1][0]);
       }else{
        return ;
       }
    }
    //post data
    function curlPost()
    {
      
       $this->domain = $this->getHost($this->loginUrl);
       $curl = curl_init();   curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
       curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   $this->joinData();
       //post data to point url
       curl_setopt($curl,CURLOPT_URL, $this->loginUrl);
       curl_setopt($curl, CURLOPT_POST, 1);
       curl_setopt($curl, CURLOPT_POSTFIELDS, $this->postData);
       curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt($curl, CURLOPT_COOKIEJAR,$this->cookiePath);
       curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookiePath);
       curl_setopt($curl,CURLOPT_REFERER, $this->referer);
       curl_setopt($curl,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($curl, CURLOPT_HEADER, true);//获取header信息
       //设定是否输出页面内容
       curl_setopt($curl, CURLOPT_NOBODY, false);
       $this->sourceUrlContents = curl_exec($curl);
       curl_close($curl);
       unset($curl);
    }
    //fetch destiny url
    function fetchUrl($destUrl = 'http://hi.baidu.com/')
    {
       $this->destUrl = $destUrl;
       $curl = curl_init();
       curl_setopt($curl, CURLOPT_URL, $destUrl);
       curl_setopt($curl, CURLOPT_HEADER, false);
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($curl, CURLOPT_COOKIEJAR, $this->cookiePath);
       curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookiePath);
       $this->destUrlContents = curl_exec($curl);
       curl_close($curl);
       unset($curl);
       return $this->destUrlContents;
    }
    //get host by url
    function getHost($url)
    {
       $urlArray = parse_url($url);
       return 'http://' . $urlArray['host'];
    }
    function templates ($title = 'Debug information', $msg)
    {
       return <<<EOF
       <fieldset id="fld_deubg" style="padding:10px;">
       <legend>{$title}</legend>
       <div id="deubg">{$msg}</div>
       </fieldset>
    EOF;
    }//debug information
    function debug($debugType = 'cookie')
    {
       switch ($debugType)
       {
        case 'cookie':
         return $this->templates('Cookie information', '<pre>' . file_get_contents($this->cookiePath) . '</pre>');
         break;
        case 'source':
         return $this->templates('Source information', $this->sourceUrlContents);
         break;
        case 'dest':
         return $this->templates('Dest information', $this->destUrlContents);
         break;
        case 'data':
         return $this->templates('Post data', $this->postData);
         break;
        case 'url':
         return $this->templates('<p>Url infomation', 'Login url' . $this->loginUrl . '</p><p>' . $this->destUrl . '</p><p>' . $this->referer . '</p>');
       }
    }//end function
    }
    $curl = new curl();
    $curl->loginUrl ='http://my.39.net/login.aspx';
    $userInfo = new stdClass();
    $userInfo->agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3';
    $userInfo->uname = 'qingxrong';
    $userInfo->pwd = 'qingrong';
    $userInfo->Host='ask.39.net';
    $userInfo->submit = '登录';
    $userInfo->action = 'login';
    $userInfo->ref = '';
    //$userInfo->referer = 'http://ask.39.net/';
    $curl->data = $userInfo;
    $curl->curlPost(); 
    $urll='http://bbs.39.net/by/forum/371-1-3.html';
    $pop='http://bbs.39.net';
    $sn=new Snoopy;
    $sn->fetch($urll);
    $rn=$sn->results;
    $zhen='/<a.*?href=\"\/by\/topic\/.*?\.html" .*?>([\s\S].*?)<\/a>/';
    $zhen2='/<a.*?href=\"(\/by\/topic\/.*?\.html)" .*?>[\s\S].*?<\/a>/';
    preg_match_all($zhen,$rn,$all);
    preg_match_all($zhen2,$rn,$all2);  
    //print_r($all[1]);
    //print_r($all2[1]);
    //echo sizeof($all[0]);
    /*
    $sum=count($all2);
    $contents=$sum-1;
    $num=$_GET[num];//处理条数
    $content=$_COOKIE[content];//当前记录
    if($num=='')
    {
      $num=1;
    }
    if($content=='')
    {
      $content=0;
    }
    */
    $sum=count($all2[1]);
    //echo $sum;
     $page=new page(array('total'=>$sum,'perpage'=>1));
     echo $page->show();
     if($_GET['PB_page']=='')
     {
       $_GET['PB_page']=1;
     }
     $num=$_GET['PB_page']-1;
    //echo $num;//echo $sm;
     $sm= $pop.$all2[1][$_GET['PB_page']];
    $zhen3='/http:\/\/bbs.39.net\/by\/topic\/(.*?)\.html/';
    preg_match_all($zhen3,$sm,$q);
    //print_r( $q[1][0]);
    //echo '<br>'.$sm;
    if($_GET['PB_page']>$sum)
    {
       print "处理完成,共处理".($num)."条记录!";
     print "<a href='untitled.php'>重来</a>";
     exit;
    }
    else
    {
    if($_POST['submit'])
    {//print_r($q[1][$content]);
    print "当前发送第".$num."条记录<br>处理网址为.".$q[1][0]."<b  style=\"color:red;\">".$all[1][$num]."</b><br/>".$_POST['content'];
    $userI = new stdClass();
    $userI->agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3';
    $userI->tid = $q[1][0];
     
    $userI->body=$_POST['content'];
    $curl->loginUrl ='http://bbs.39.net/web/topic.asmx/addreplynew';
    $curl->data = $userI;
    $curl->curlPost();
    }
     }
      
     
     
    /*
                                                                            //=========================================================== /*
    http://bbs.39.net/by/topic/1241495.html 这个页面看效果
    */?>
    <?php 
     $num=$_GET['PB_page']-1;
    ?>
    <form action="" method="post" name="frmpost">  <div>标题:<input type="text" name="title"  style="width:670px" value=" <?php print $all[1][$num];?>"/></div>
       <div> <textarea cols="100" rows="10" name='content' ></textarea></div>
      <div>发送后测试是否成功的网址:<input type="text" name='links' style="width:510px" value="<?php print $sm;?>"/></div>                   
       <div  style="float:right; width:820px;">
     
        <input  type="submit" name="submit" value="登陆" /> </div>
            </form>