理解HTTP消息头:http://www.cnblogs.com/jacktu/archive/2008/01/16/1041710.html
PHP中伪造HTTP_REFERER代码:http://www.phperz.com/php/meirijiqiao/12202Z220102902.html
详解PHP fsockopen的使用方法:http://developer.51cto.com/art/200912/166333.htm
1、使用fsockopen()自己生成http头来访问页面。
POST方式代码如下:
<?php
$hostname="localhost";
$port=80;
$timeout=30;
$param="test=".urlencode("hello");
$length=strlen($param);
$fp=fsockopen($hostname,$port,$errno,$errstr,$timeout);
$out="POST /temp/http/newfile.php HTTP/1.1\r\n";
$out.="Host:localhost\r\n";
$out.="Referer:http://www.baidu.com\r\n";
$out.="Content-Type: application/x-www-form-urlencoded\r\n";
$out.="Content-Length:".$length."\r\n";
$out.="User-agent:Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20100101 Firefox/8.0\r\n";
$out.="Connection:Close\r\n\r\n";
$out.=$param."\r\n";
fwrite($fp, $out);
while(!feof($fp)){
echo fgets($fp,128);
}
echo fread($fp,10000);
fclose($fp);