php+socket模拟get,post请求
2013-12-31 08:55
429 查看
它可以伪造c
ookie,refefer头信息,可以用于批量发贴。数据采集。
<?php class Http { public $requestUrlInfo=array(); public $requestLine;//请求行 public $requestHeader=array();//请求头信息 public $requestBody;//请求主体信息 public $fh=null; /** * 分析 url 并且连接上url */ public function __construct($url){ $this->requestUrlInfo=parse_url($url); if(!isset($this->requestUrlInfo['port'])){ $this->requestUrlInfo['port']=80; } if(!isset($this->requestUrlInfo['path'])){ $this->requestUrlInfo['path']='/'; } $this->fh=fsockopen($this->requestUrlInfo['host'],$this->requestUrlInfo['port']); } /** * 构造 请求行和请求头,主体信息 * @param unknown_type $method * @param unknown_type $url */ public function writeReqeustLineAndHeaderAndBody($method="GET",$postParameters=array()){ set_time_limit(0); $this->requestLine=$method.' '.$this->requestUrlInfo['path'].'?'.$this->requestUrlInfo['query'].' HTTP/1.1'; $this->requestHeader[]='Host:'.$this->requestUrlInfo['host']; if($method=='POST'){ $this->requestHeader[]='Content-Type:application/x-www-form-urlencoded'; $this->requestBody=http_build_query($postParameters); $this->requestHeader[]='Content-Length:'.strlen($this->requestBody); } $arr=array_merge(array($this->requestLine),$this->requestHeader,array(''),array($this->requestBody),array('')); $str=implode("\r\n",$arr); fwrite($this->fh, $str); $response=''; while (!feof($this->fh)){ $response.=fread($this->fh,1024); } fclose($this->fh); return $response; } public function setHeader($str){ $this->requestHeader[]=$str; } } ?>
ookie,refefer头信息,可以用于批量发贴。数据采集。
相关文章推荐
- php获取服务器时间的代码
- php定时计划任务的例子
- PHP通过IP 获取 地理位置(实例)
- 整理一些有意思的php笔试题
- Windows下使用composer安装Laravel框架卡住,解决方案
- 如何在BAE3.0上安装yaf扩展
- 用命令行发邮件——让你更加了解smtp
- 第六章_PHP数组(二)
- codeigniter使用技巧批量插入数据实例方法分享
- php curl模拟post提交数据示例
- 不用重装PHP也可以添加extension包的方法
- php5 在vps小内存上安装报错解决
- ThinkPHP的数据表操作
- PHP基础之 重载 的实现方式
- PHP基础之 继承(一)
- PHP 数组的遍历的几种方式(以及foreach与for/while+each效率的比较)
- PHP基础 数组函数 的总结
- 第六章_PHP数组
- PHP 一维数组转二维数组
- php 2038 时间 time() date() 问题