日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php模拟用户自动在qq空间发表文章的方法

發(fā)布時間:2023/12/16 php 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php模拟用户自动在qq空间发表文章的方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我們這里是一個簡單的利用php來模擬登錄后再到QQ空間發(fā)送文章的一個簡單的程序,有需要的朋友可以參考,或改進可以給我意見,代碼如下:


<?php //模擬get post請求函數(shù) http://www.lai18.com/* 函數(shù)說明: 功能:請求方式可以get,post,可以發(fā)送的cookie,保存的cookiefile文件 參數(shù):$url-----請求url $referer---來源url $postdata----------用于post請求的數(shù)據(jù),''為get請求 $cookie---------發(fā)送的cookie $cookiefile-----保存的cookiefile文件 返回值:返回獲取的源碼 */ function request($url,$referer='',$postdata='',$cookie='',$cookiefile=''){ //header設置 $header=''; $header.="Content-Type: application/x-www-form-urlencodedrn";//內容請求類型 $header.="User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)rn";//瀏覽器字段 $header.="Referer:".$referer."rn";//設置來源地址 $header .= "Cookie:".$cookie ; //設置cookie,默認空 //請求方法get post,通過$postdata空---get,非空----post if($postdata=='')$method='GET'; else $method='POST'; //定義用于創(chuàng)建流的數(shù)組 $opts=array(); $opts['http']=array('method'=>$method,'header'=>$header,'content'=>$postdata); //生成流 $context=stream_context_create($opts); //發(fā)送請求,獲取源碼 $yuanma=file_get_contents($url,false,$context); //是否需要保存cookie到文件,$cookiefile不空時 if($cookiefile!=''){ echo '需要保存cookie<br>'; //判斷保存文件存在,不存在創(chuàng)建 if(!file_exists($cookiefile)){ file_put_contents($cookiefile,''); } //獲取cookie,保存起來 $response=implode("rn",$http_response_header); //用正則匹配cookie $zengze="/Set-Cookie:(.*?)rn/"; preg_match_all($zengze,$response,$cookie_arr); //存在匹配,保存 if(!emptyempty($cookie_arr[1])){ $cookiestr=implode(';',$cookie_arr[1]); file_put_contents($cookiefile,$cookiestr); echo '成功保存cookie<br>'; } else echo '沒有匹配到cookie<br>'; }//end if($cookiefile!='') //返回源碼 return $yuanma; }//end function request($url,$referer,$postdata,$cookie,$cookiefile) //獲得當前的腳本網(wǎng)址 function GetCurUrl() { if(!emptyempty($_SERVER["REQUEST_URI"])) { $scriptName = $_SERVER["REQUEST_URI"]; $nowurl = $scriptName; } else { $scriptName = $_SERVER["PHP_SELF"]; if(emptyempty($_SERVER["QUERY_STRING"])) { $nowurl = $scriptName; } else { $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"]; } } return $nowurl; } //獲得當前文件名 $nowurl=GetCurUrl(); //echo $nowurl; //表單輸出,沒有提交時 if(!isset($_POST['qq'])){ echo '<form method="post" action="'.$nowurl.'"> qq號碼:<input type="text" name="qq"><br> g_tk:<input type="text" name="g_tk"><br> 標題:<input type="text" name="title"><br> 內容:<input type="text" name="content"><br> <input type="submit" value="發(fā)表文章"> </form>'; die(); } /* 提交參數(shù)說明: $_POST['qq']---用戶QQ $_POST['g_tk']--這個參數(shù)很關鍵,獲得這個參數(shù),需要抓下發(fā)表時提交的post地址后面調用的g_tk=123456789, 路POST <a href="http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789里的g_tk=123456789" target="_blank">http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789里的g_tk=123456789</a> $_POST['title']---文章標題,不得空 $_POST['content']---文章內容,不得空 */ header('Content-Type:text/html;charset=gb2312'); set_time_limit(0); //ob_end_clean(); //ob_start(); //獲取cookie文件,不存在創(chuàng)建,并退出程序 $cookiefile=dirname(__FILE__).'\qq_cookie.txt'; if(!file_exists($cookiefile)){ echo 'qq_cookie.txt不存在,自動創(chuàng)建,請?zhí)顚懽グ腸ookie<br>'; file_put_contents($cookiefile,''); die('程序退出'); } //存在,讀取cookie else{ $cookie=file_get_contents($cookiefile);//登錄cookie //$cookie=urlencode($cookie); } //echo 'cookie:'.$cookie.'<br>'; //構成發(fā)表頁,post數(shù)據(jù)等的重要信息 //qq號碼 if(emptyempty($_POST['qq'])||preg_match('/[^0-9]/is',$_POST['qq']))die('qq號碼有誤,必須數(shù)字'); else $qq=$_POST['qq'];//qq號 if(emptyempty($_POST['g_tk'])||preg_match('/[^0-9]/is',$_POST['g_tk']))die('post重要參數(shù)g_tk不合法,必須數(shù)字,請使用抓包的值'); $g_tk=$_POST['g_tk']; $title=emptyempty($_POST['title'])?die('標題不得空'):$_POST['title'];//文章標題 $content=emptyempty($_POST['content'])?die('內容不得空'):$_POST['content'];//內容 $category='個人日記';//分類 $fabiao='http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk='.$g_tk;//發(fā)表處理頁 $referer='http://ctc.qzs.qq.com/qzone/v5/toolpages/fp_gbk.html';//來源頁 $r1='http://user.qzone.qq.com/'.$qq.'/infocenter';//列表訪問來源頁 $postdata='uin='.$qq.'&category='.urlencode($category).'&title='.urlencode($title).'&content='.urlencode($content).'&html='.urlencode('<div class="blog_details_20110920">'.$content.'</div>').'&tweetflag=0&cb_autograph=1&topflag=0&needfeed=0&g_tk='.$g_tk.'&_fp_refer=http%3A%2F%2Fctc.qzs.qq.com%2Fqzone%2Fnewblog%2Fv5%2Feditor.html%3Fsource%3D1%7Chttp%3A%2F%2Fctc.qzs.qq.com%2Fqzone%2Fnewblog%2Fv5%2Feditor.html%3Fsource%3D1%3Chttp%3A%2F%2Fuser.qzone.qq.com%2F'.$qq.'%2Fmain';//post數(shù)據(jù) //$postdata=urlencode($postdata); //echo $postdata; //發(fā)送請求,獲取源碼 $yuanma=request($fabiao,$r1,$postdata,$cookie,''); if(strpos($yuanma,'發(fā)表成功'))echo $title.' 發(fā)表成功<br>'; else echo '發(fā)表失敗:右鍵查看源碼,可以看到具體錯誤'.$yuanma; ?>

代碼僅供參考,成功率有待大家的驗證,有問題可以在本博文下回復或留言:http://www.lai18.com/content/368902.html

總結

以上是生活随笔為你收集整理的php模拟用户自动在qq空间发表文章的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。