Home Backend Development PHP Tutorial php模拟用户自动在qq空间发表文章的步骤

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

Jun 13, 2016 pm 12:18 PM
cookie nbsp post

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

我们这里是一个简单的利用php来模拟登录后再到QQ空间发送文章的一个简单的程序,有需要的朋友可以参考,或改进可以给我意见,代码如下:

 

 

[php] view plaincopy

 

  1.   
  2. //模拟get post请求函数 http://www.lai18.com  
  3.   
  4. /*  
  5.  
  6. 函数说明:  
  7.  
  8. 功能:请求方式可以get,post,可以发送的cookie,保存的cookiefile文件  
  9.  
  10. 参数:$url-----请求url    $referer---来源url    $postdata----------用于post请求的数据,''为get请求  
  11.  
  12. $cookie---------发送的cookie     $cookiefile-----保存的cookiefile文件  
  13.  
  14. 返回值:返回获取的源码  
  15.  
  16. */   
  17.   
  18. function request($url,$referer='',$postdata='',$cookie='',$cookiefile=''){   
  19.   
  20. //header设置   
  21.   
  22. $header='';   
  23.   
  24. $header.="Content-Type: application/x-www-form-urlencodedrn";//内容请求类型   
  25.   
  26. $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";//浏览器字段   
  27.   
  28. $header.="Referer:".$referer."rn";//设置来源地址   
  29.   
  30. $header .= "Cookie:".$cookie ; //设置cookie,默认空   
  31.   
  32. //请求方法get post,通过$postdata空---get,非空----post   
  33.   
  34. if($postdata=='')$method='GET';   
  35.   
  36. else $method='POST';   
  37.   
  38. //定义用于创建流的数组   
  39.   
  40. $opts=array();   
  41.   
  42. $opts['http']=array('method'=>$method,'header'=>$header,'content'=>$postdata);   
  43.   
  44. //生成流   
  45.   
  46. $context=stream_context_create($opts);   
  47.   
  48. //发送请求,获取源码   
  49.   
  50. $yuanma=file_get_contents($url,false,$context);   
  51.   
  52. //是否需要保存cookie到文件,$cookiefile不空时   
  53.   
  54. if($cookiefile!=''){   
  55.   
  56. echo '需要保存cookie
    ';   
  57.   
  58. //判断保存文件存在,不存在创建   
  59.   
  60. if(!file_exists($cookiefile)){   
  61.   
  62. file_put_contents($cookiefile,'');   
  63.   
  64. }   
  65.   
  66. //获取cookie,保存起来   
  67.   
  68. $response=implode("rn",$http_response_header);   
  69.   
  70. //用正则匹配cookie   
  71.   
  72. $zengze="/Set-Cookie:(.*?)rn/";   
  73.   
  74. preg_match_all($zengze,$response,$cookie_arr);   
  75.   
  76. //存在匹配,保存   
  77.   
  78. if(!emptyempty($cookie_arr[1])){   
  79.   
  80. $cookiestr=implode(';',$cookie_arr[1]);   
  81.   
  82. file_put_contents($cookiefile,$cookiestr);   
  83.   
  84. echo '成功保存cookie
    ';   
  85.   
  86. }   
  87.   
  88. else echo '没有匹配到cookie
    ';   
  89.   
  90. }//end if($cookiefile!='')   
  91.   
  92. //返回源码   
  93.   
  94. return $yuanma;   
  95.   
  96. }//end function request($url,$referer,$postdata,$cookie,$cookiefile)    
  97.   
  98. //获得当前的脚本网址    
  99.   
  100. function GetCurUrl()    
  101.   
  102. {    
  103.   
  104. if(!emptyempty($_SERVER["REQUEST_URI"]))    
  105.   
  106. {    
  107.   
  108. $scriptName = $_SERVER["REQUEST_URI"];    
  109.   
  110. $nowurl = $scriptName;    
  111.   
  112. }    
  113.   
  114. else    
  115.   
  116. {    
  117.   
  118. $scriptName = $_SERVER["PHP_SELF"];    
  119.   
  120. if(emptyempty($_SERVER["QUERY_STRING"]))    
  121.   
  122. {    
  123.   
  124. $nowurl = $scriptName;    
  125.   
  126. }    
  127.   
  128. else    
  129.   
  130. {    
  131.   
  132. $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];    
  133.   
  134. }    
  135.   
  136. }    
  137.   
  138. return $nowurl;    
  139.   
  140. }   
  141.   
  142.    
  143.   
  144. //获得当前文件名   
  145.   
  146. $nowurl=GetCurUrl();   
  147.   
  148. //echo $nowurl;   
  149.   
  150.    
  151.   
  152. //表单输出,没有提交时   
  153.   
  154. if(!isset($_POST['qq'])){   
  155.   
  156. echo '
    .$nowurl.'">   
  157.   
  158. qq号码:"text" name="qq">
       
  159.   
  160. g_tk:"text" name="g_tk">
       
  161.   
  162. 标题:"text" name="title">
       
  163.   
  164. 内容:"text" name="content">
       
  165.   
  166. "submit" value="发表文章">   
  167.   
  168. ';   
  169.   
  170. die();   
  171.   
  172. }   
  173.   
  174.    
  175.   
  176. /*  
  177.  
  178. 提交参数说明:  
  179.  
  180. $_POST['qq']---用户QQ  
  181.  
  182. $_POST['g_tk']--这个参数很关键,获得这个参数,需要抓下发表时提交的post地址后面调用的g_tk=123456789,  
  183.  
  184. 路POST http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk=123456789里的g_tk=123456789  
  185.  
  186. $_POST['title']---文章标题,不得空  
  187.  
  188. $_POST['content']---文章内容,不得空  
  189.  
  190. */   
  191.   
  192.    
  193.   
  194. header('Content-Type:text/html;charset=gb2312');   
  195.   
  196. set_time_limit(0);   
  197.   
  198. //ob_end_clean();   
  199.   
  200. //ob_start();   
  201.   
  202.    
  203.   
  204. //获取cookie文件,不存在创建,并退出程序   
  205.   
  206. $cookiefile=dirname(__FILE__).'\qq_cookie.txt';   
  207.   
  208. if(!file_exists($cookiefile)){   
  209.   
  210. echo 'qq_cookie.txt不存在,自动创建,请填写抓包的cookie
    ';   
  211.   
  212. file_put_contents($cookiefile,'');   
  213.   
  214. die('程序退出');   
  215.   
  216. }   
  217.   
  218. //存在,读取cookie   
  219.   
  220. else{   
  221.   
  222. $cookie=file_get_contents($cookiefile);//登录cookie   
  223.   
  224. //$cookie=urlencode($cookie);   
  225.   
  226. }   
  227.   
  228. //echo 'cookie:'.$cookie.'
    ';   
  229.   
  230.    
  231.   
  232. //构成发表页,post数据等的重要信息   
  233.   
  234. //qq号码   
  235.   
  236. if(emptyempty($_POST['qq'])||preg_match('/[^0-9]/is',$_POST['qq']))die('qq号码有误,必须数字');   
  237.   
  238. else $qq=$_POST['qq'];//qq号   
  239.   
  240. if(emptyempty($_POST['g_tk'])||preg_match('/[^0-9]/is',$_POST['g_tk']))die('post重要参数g_tk不合法,必须数字,请使用抓包的值');   
  241.   
  242. $g_tk=$_POST['g_tk'];   
  243.   
  244.    
  245.   
  246. $title=emptyempty($_POST['title'])?die('标题不得空'):$_POST['title'];//文章标题   
  247.   
  248. $content=emptyempty($_POST['content'])?die('内容不得空'):$_POST['content'];//内容   
  249.   
  250.    
  251.   
  252. $category='个人日记';//分类   
  253.   
  254. $fabiao='http://b1.qzone.qq.com/cgi-bin/blognew/blog_add?g_tk='.$g_tk;//发表处理页   
  255.   
  256. $referer='http://ctc.qzs.qq.com/qzone/v5/toolpages/fp_gbk.html';//来源页   
  257.   
  258. $r1='http://user.qzone.qq.com/'.$qq.'/infocenter';//列表访问来源页   
  259.   
  260. $postdata='uin='.$qq.'&category='.urlencode($category).'&title='.urlencode($title).'&content='.urlencode($content).'&html='.urlencode('
    '.$content.'
    ').'&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数据   
  261.   
  262. //$postdata=urlencode($postdata);   
  263.   
  264. //echo $postdata;   
  265.   
  266. //发送请求,获取源码   
  267.   
  268. $yuanma=request($fabiao,$r1,$postdata,$cookie,'');   
  269.   
  270. if(strpos($yuanma,'发表成功'))echo $title.'  发表成功
    ';   
  271.   
  272. else echo '发表失败:右键查看源码,可以看到具体错误'.$yuanma;   
  273.   
  274. ?>  

 

 

代码仅供参考,成功率有待大家的验证

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

Where are cookies stored? Where are cookies stored? Dec 20, 2023 pm 03:07 PM

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Where are the cookies on your computer? Where are the cookies on your computer? Dec 22, 2023 pm 03:46 PM

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

How to Hide and Unhide Folders on Windows 11 [3 Ways] How to Hide and Unhide Folders on Windows 11 [3 Ways] Sep 23, 2023 am 08:37 AM

Hiding folders is a great way to keep your desktop organized. Maybe you want to keep your personal files or some client details away from prying eyes. Whatever it is, the ability to put them away and unhide them when necessary is a big saver. In short, these hidden files will not show up in the main menu, but they will still be accessible. It's very simple and shouldn't take you too much time. How to hide a folder in Windows 11? 1. Use File Explorer and hit the + key to open File Explorer. WindowsE Find the folder you want to hide, right-click it and select Properties. Navigate to the General tab, check the Hide box, click Apply, and then click OK. In the next dialog box, check Apply changes to this folder, sub-folder

See all articles