Copy Code code as follows:
<?php
post.php
function Post ($host, $port)
{
$host = "127.0.0.1";
Establish a connection
$conn = Fsockopen ($host, $port);
if (! $conn)
{
Die ("Con error");
}
Loop 5 times to send data
//
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 is the key.
$header. = "connection:keep-alive\r\n\r\n";
$header. = "{$data}\r\n\r\n";
Fwrite ($conn, $header);
Take the result
$result = ';
while (!feof ($conn))
//{
$result. = Fgets ($conn, 128);
//}
return $result;
}
Post (' 127.0.0.1 ', 80);
?>
Copy Code code as follows:
<?php
test.php
$fp = fopen (' Result.txt ', ' a ');
$data = $_post[' user_name ']. "--". Date (' y-m-d h:i:s '). " \ r \ n ";
Fwrite ($fp, $data);
Fclose ($FP);
?>