Copy codeThe Code is 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 ");
}
// Send data 5 times in a loop
//
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 ";
$ Header. = "{$ data} \ r \ n ";
Fwrite ($ conn, $ header );
// Obtain the result
// $ Result = '';
// While (! Feof ($ conn ))
//{
// $ Result. = fgets ($ conn, 128 );
//}
// Return $ result;
}
Post ('1970. 0.0.1 ', 80 );
?>
Copy codeThe Code is 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 );
?>