php模拟用户自动在qq空间发表文章的方法
我们这里是一个简单的利用php来模拟登录后再到QQ空间发送文章的一个简单的程序,有需要的朋友可以参考,或改进可以给我意见,代码如下:
<?php //模拟get post请求函数 http://www.lai18.com/* 函数说明: 功能:请求方式可以get,post,可以发送的cookie,保存的cookiefile文件 参数:$url-----请求url $referer---来源url $postdata----------用于post请求的数据,''为get请求 $cookie---------发送的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'; //定义用于创建流的数组 $opts=array(); $opts['http']=array('method'=>$method,'header'=>$header,'content'=>$postdata); //生成流 $context=stream_context_create($opts); //发送请求,获取源码 $yuanma=file_get_contents($url,false,$context); //是否需要保存cookie到文件,$cookiefile不空时 if($cookiefile!=''){ echo '需要保存cookie<br>'; //判断保存文件存在,不存在创建 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) //获得当前的脚本网址 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 '
'; file_put_contents($cookiefile,''); die('程序退出'); } //存在,读取cookie else{ $cookie=file_get_contents($cookiefile);//登录cookie //$cookie=urlencode($cookie); } //echo 'cookie:'.$cookie.'
'; //构成发表页,post数据等的重要信息 //qq号码 if(emptyempty($_POST['qq'])||preg_match('/[^0-9]/is',$_POST['qq']))die('qq号码有误,必须数字'); else $qq=$_POST['qq'];//qq号 if(emptyempty($_POST['g_tk'])||preg_match('/[^0-9]/is',$_POST['g_tk']))die('post重要参数g_tk不合法,必须数字,请使用抓包的值'); $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;//发表处理页 $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('
'; else echo '发表失败:右键查看源码,可以看到具体错误'.$yuanma; ?>
代码仅供参考,成功率有待大家的验证,有问题可以在本博文下回复或留言:http://www.lai18.com/content/368902.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
