//post.php
function Post($host,$port)
{
//$host="127.0.0.1";
//建立连接
$conn = fsockopen($host,$port);
if (!$conn)
{
die("Con 错误");
}
//循环发送5次数据
//
for($i = 0;$i{
$data="user_name=管理员".$i;
WriteData($conn,$host,$data);
回显 $i。"
";
}
fclose($conn);
}
函数 WriteData($conn,$host,$data)
{
$header = "POST /test.php HTTP/1.1rn";
$header.= "主机: {$host}rn";
$header.= "内容类型:application/x-www-form-urlencodedrn";
$header.= "内容长度:".strlen($data)."rn";
//Keep-Alive是关键
$header.= "Connection: Keep-Alivenrn";
$header.= "{$data}rnrn";
fwrite($conn,$header);
//获取结果
//$result = '';
//while(!feof($conn))
//{
// $result .= fgets($conn,128);
//}
//返回$结果;
}
发布('127.0.0.1',80);
?>
//test.php
$fp = fopen('result.txt','a');
$data = $_POST['user_name']." -- ".日期('Y-m-d H:i:s')."rn";
fwrite($fp,$data);
fclose($fp);
?>