Html form php mimic.
Posted: Fri Aug 24, 2007 2:06 pm
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;
}
?>Code: Select all
<form action="$address" method="post">
<!-- $data should be an array of fields -->
</form>