Page 1 of 1

Html form php mimic.

Posted: Fri Aug 24, 2007 2:06 pm
by JellyFish

Code: Select all

<?php
	function HttpRequest($address, $data)
	{
		$url = parse_url($address);
		
		while (list($key, $value) = each($data))
		{
			$dataToPost .= "$key=$value&";
		}
		$dataToPost = rtrim($dataToPost, "&");
		
		$request = 	"POST ".$url['path']." HTTP/1.0\r\n"
							. "Host: ".$url['host']."\r\n"
							. "Content-Type: application/x-www-form-urlencoded;\r\n"
							. "Content-Length: ".strlen($dataToPost)."\r\n"
							. "\r\n"
							. $dataToPost;
		
		$socket = @fsockopen($url['host'], 80, $errno, $errstr) or die("Error: unable to open a socket connection with ".$url['host']."\n $errno: $errstr");
		fwrite($socket, $request);
		
		// Response
		$response = '';
		while (!feof($socket)) {
		    $response .= fpassthru($socket);
		}
		fclose($socket);
		
		return $response;
	}
?>
Will this function be equivalent to:

Code: Select all

<form action="$address" method="post">
<!-- $data should be an array of fields -->
</form>
So will the above function send a request just the same as an html form would?

Posted: Fri Aug 24, 2007 4:14 pm
by feyd
You're going to have to read the RFC documentation on the protocols you are going to use to determine whether it's matches what you hope.

Posted: Fri Aug 24, 2007 4:46 pm
by JellyFish
feyd wrote:You're going to have to read the RFC documentation on the protocols you are going to use to determine whether it's matches what you hope.
I googled RFC documentation. I get http://cpan.uwinnipeg.ca/htdocs/SAP-Rfc/. I don't understand what it is. What is RFC?