php下POST报文到主机 ,posting提交利用代码
<?
/*
** POST报文到主机
*/
fungsi PostToHost($url, $data) {
$url = parse_url($url);
if (!$url) return "tidak dapat mengurai url";
if (!isset($url['port'])) { $url['port'] = ""; }
if (!isset($url['query'])) { $url['query'] = ""; }
$dikodekan = "";
while (daftar($k,$v) = masing-masing($data)) {
$dikodekan .= ($dikodekan ? "&" : "");
$dikodekan .= rawurlencode($k)."=".rawurlencode($v);
}
$pelabuhan = $url['pelabuhan'] ? $url['pelabuhan'] : 80;
$fp = fsockopen($url['host'], $port, $errno, $errstr);
if (!$fp) return "Gagal membuka soket ke $url[host] $port ERROR: $errno - $errstr";
fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['kueri']));
fputs($fp, "Host: $url[host]\n");
fputs($fp, "Jenis konten: application/x-www-form-urlencoded\n");
fputs($fp, "Panjang konten: " . strlen($dikodekan) . " \n ");
fputs($fp, "Koneksi: tutup\n\n");
fputs($fp, "$dikodekan\n");
$baris = fget($fp,1024);
if (!eregi("^HTTP/1\..200", $line)) kembali;
$hasil = ""; $inheader = 1;
while(!feof($fp)) {
$baris = fget($fp,1024);
if ($inheader && ($line == " \n " || $line == " \r\n ")) {
$inheader = 0;
}
elseif (!$inheader) {
$hasil .= $baris;
}
}
fclose($fp);
kembalikan $hasil;
}/* fungsi akhir PostToHost */
?>