代码如下:
zuojiankuohaophpcn?php
//post.php
function post($host,$port)
{
//$host="127.0.0.1";
//建立连接
$conn = fsockopen($host,$port);
if (!$conn)
{
die("con error");
}
//循环发送5次数据
//
for($i = 0;$i<5;$i++)
{
$data="user_name=admin".$i;
writedata($conn,$host,$data);
echo $i."<br />";
}
fclose($conn);
}
function writedata($conn,$host,$data)
{
$header = "post /test.php http/1.1\r\n";
$header.= "host : {$host}\r\n";
$header.= "content-type: application/x-www-form-urlencoded\r\n";
$header.= "content-length:".strlen($data)."\r\n";
//keep-alive是关键
$header.= "connection: keep-alive\r\n\r\n";
$header.= "{$data}\r\n\r\n";
fwrite($conn,$header);
//取结果
//$result = '';
//while(!feof($conn))
//{
// $result .= fgets($conn,128);
/
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号