它可以伪造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头信息,可以用于批量发贴。数据采集。