Return to Snippet

Revision: 10415
at December 28, 2008 04:24 by Wiederkehr


Initial Code
<?php
function PostToHost($host, $path, $referer, $data_to_send) {
	$fp = fsockopen($host, 80);
	printf("Open!n");
	fputs($fp, "POST $path HTTP/1.1rn");
	fputs($fp, "Host: $hostrn");
	fputs($fp, "Referer: $refererrn");
	fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
	fputs($fp, "Content-length: ". strlen($data_to_send) ."rn");
	fputs($fp, "Connection: closernrn");
	fputs($fp, $data_to_send);
	printf("Sent!n");
	while(!feof($fp)) {
		$res .= fgets($fp, 128);
	}
	printf("Done!n");
	fclose($fp);
	return $res;
}

$data = "data";

printf("Go!n");
$x = PostToHost(
	"host",
	"path",
	"referer",
$data
	);
?>

Initial URL

                                

Initial Description

                                

Initial Title
PHP POST Request

Initial Tags
http, php, textmate, post

Initial Language
PHP