Html form php mimic.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Html form php mimic.

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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?
Post Reply