- 在线时间
- 852 小时
- 最后登录
- 2014-5-17
- 阅读权限
- 40
- 积分
- 1167
- UID
- 358
- 注册时间
- 2000-12-23
- 帖子
- 896
- 精华
- 0
|
用php写的,curl模块
执行:php -q $script_name- <?php
- set_time_limit(0);
- function bbs_login($ch , $uname , $passwd , $formhash , $cookietime , $referer){
- $url = 'http://yknet28.8866.org/logging.php?action=login&loginsubmit=true' ;
- $postfields = 'formhash=' . $formhash . '&cookietime=' . $cookietime . '&loginfield=username&username=' . $uname . '&password=' . $passwd . '&userlogin=true' ;
- //print $postfields ;
- $options = array(CURLOPT_URL => $url,
- CURLOPT_HEADER => 0,
- CURLOPT_NOBODY => 0,
- CURLOPT_PORT => 80,
- CURLOPT_POST => 1,
- CURLOPT_POSTFIELDS => $postfields,
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_FOLLOWLOCATION => 1,
- CURLOPT_COOKIEJAR => 'c:\windows\temp\highot' ,
- CURLOPT_COOKIEFILE => 'c:\windows\temp\highot' ,
- CURLOPT_REFERER => $referer
- ) ;
- curl_setopt_array($ch, $options);
- $code = curl_exec($ch) ;
- $info = curl_getinfo($ch) ;
- if ($code === false || $info['http_code'] != 200){
- $code = "No cURL data returned for $url [". $info['http_code']. "]";
- if (curl_error($ch)){
- $code .= "\n". curl_error($ch) ;
- //print $code ;
- exit(-1) ;
- }
- }
- else{
- $url = 'http://yknet28.8866.org/' ;
- curl_setopt($ch , CURLOPT_URL , $url) ;
- curl_setopt($ch , CURLOPT_HEADER , 0) ;
- curl_setopt($ch , CURLOPT_RETURNTRANSFER , 1) ;
- $code = curl_exec($ch) ;
- return $code ;
- }
- }
- function bbs_post($ch , $formhash , $subject , $message , $topicsubmit , $referer){
- $url = 'http://yknet28.8866.org/post.php?action=newthread&fid=71&extra=page%3D1&topicsubmit=yes' ;
- $postfields = 'formhash=' . $formhash . '&subject=' . $subject . '&message=' . $message . '&topicsubmit=' . $topicsubmit ;
- print $postfields ;
- $options = array(CURLOPT_URL => $url,
- CURLOPT_HEADER => 0,
- CURLOPT_NOBODY => 0,
- CURLOPT_PORT => 80,
- CURLOPT_POST => 1,
- CURLOPT_POSTFIELDS => $postfields,
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_FOLLOWLOCATION => 1,
- CURLOPT_COOKIEJAR => 'c:\windows\temp\highot' ,
- CURLOPT_COOKIEFILE => 'c:\windows\temp\highot' ,
- CURLOPT_REFERER => $referer
- ) ;
- curl_setopt_array($ch, $options);
- $code = curl_exec($ch) ;
- $info = curl_getinfo($ch) ;
- if ($code === false || $info['http_code'] != 200){
- $code = "No cURL data returned for $url [". $info['http_code']. "]";
- if (curl_error($ch)){
- $code .= "\n". curl_error($ch) ;
- print $code ;
- exit(-1) ;
- }
- }
- else return $code ;
- }
- $uname = "" ; //[color=Red]这儿要写你的用户名[/color]
- $passwd = "" ;//[color=Red]这儿要写密码[/color]
- $formhash = "" ;
- $ch = curl_init() ;
- $url = 'http://yknet28.8866.org/' ;
- curl_setopt($ch , CURLOPT_URL , $url) ;
- curl_setopt($ch , CURLOPT_HEADER , 0) ;
- curl_setopt($ch , CURLOPT_RETURNTRANSFER , 1) ;
- $code = curl_exec($ch) ;
- //print $code ;
- if(!$code){
- print "first error\n" ;
- exit(-1) ;
- }
- $pattern = '/<button\s+name=\"userlogin\"\s+type=\"submit\"\s+value=\"true\">登录<\/button>/' ;
- if(preg_match($pattern , $code)){
- $pattern = '/<input\s+type=\"hidden\"\s+name=\"formhash\"\s+value=\"(\w+)\"\s+\/>/' ;
- if(!preg_match($pattern , $code , $matches)){
- curl_close($ch) ;
- print "pattern error 0\n" ;
- exit(-1) ;
- }
- $formhash = $matches[1] ;
- $pattern = '/<input\s+type=\"hidden\"\s+name=\"cookietime\"\s+value=\"(\d+)\"\s+\/>/' ;
- if(!preg_match($pattern , $code , $matches)){
- curl_close($ch) ;
- print "pattern error 1\n" ;
- exit(-1) ;
- }
- $cookietime = $matches[1] ;
- //print "formhash = " . $formhash . "\n" ;
- //print "cookie = " . $cookietime . "\n" ;
- $code = bbs_login($ch , $uname , $passwd , $formhash , $cookietime , '') ;
- //print $code ;
- }
- $pattern = '/<a href=\"logging.php\?action=logout&formhash=(\w+)\" class=\"notabs\">退出<\/a>/' ;
- if(preg_match($pattern , $code , $matches)) $formhash = $matches[1] ;
- print "formhash = " . $formhash ;
- $code = bbs_post($ch , $formhash , "test" , "test0000" , '' , '') ;//test是主题;test0000是内容,可以更改
- //print $code ;
- curl_close($ch);
- ?>
复制代码
[ 本帖最后由 judite 于 2009-1-3 20:41 编辑 ] |
-
总评分: 银币 + 30
金币 + 30
查看全部评分
|