본문 바로가기
웹프로그램

PHP 소켓 통신

by 세이박스 2008. 10. 19.
반응형
$host = 'ddiass.pe.kr';
$service_uri = '/test.html';
$vars ='?var=kkk';

# compose HTTP request header
$header = "Host: $host\r\n";
$header .= "User-Agent: PHP Script-x\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($vars)."\r\n";
$header .= "Connection: close\r\n\r\n";

$fp = pfsockopen($host, 80, $errno, $errstr);
if (!$fp) {
echo "$errstr ($errno)<br/>\n";
// echo $fp;
} else {
fputs($fp, "POST $service_uri HTTP/1.1\r\n");
fputs($fp, $header.$vars);
fwrite($fp, $out);
/*while (!feof($fp)) {
echo fgets($fp, 128);
}*/
fclose($fp);
}
반응형