HTML form, submit 없이 post로 넘기기

2006/06/09 18:38

출처:
http://shiflett.org/hacks/php/http_post

소켓으로 연결 해서 넘기는 방식 임다.
http_post

Discussion
This is a simple function that allows you to send an HTTP POST request to a Web server, whether local or

remote. It takes three arguments:

The host where the request is sent
The path of the resource that is receiving the request
The raw POST data to send
The function returns the raw HTTP response. Parse this as needed.

Listing
<?
function http_post($host, $path, $data)
{
  
$http_response = '';
  
$content_length = strlen($data);
  
$fp = fsockopen($host, 80);
  
fputs($fp, "POST $path HTTP/1.1\r\n");
  
fputs($fp, "Host: $host\r\n");
  
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
  
fputs($fp, "Content-Length: $content_length\r\n");
  
fputs($fp, "Connection: close\r\n\r\n");
  
fputs($fp, $data);
   while (!
feof($fp))
   {
       
$http_response .= fgets($fp, 128);
   }
  
fclose($fp);

   return
$http_response;
}
?>

Example
$http_response = http_post('example.org', '/path/to/script.php', 'first_name=chris&last_name=shiflett');

Comments
Comments are not available yet.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)

Trackback

Trackback Address :: http://mostech.zzlzzl.net/trackback/69