Forum Moderators: coopster
Making POSTs from a wab script is probably a fairly unusual thing to do, but it seems like I shouldn't be the first person to need it. Of course, I can implement it myself if I have to, but I'd rather use a canned solution if there is one.
Should have submitted this before finishing dinner. Now AaronC beat me to it.
<?php
// function to read server name
function servername($txt)
{
if (substr(strtoupper($txt),0,4)=="WWW.")
$txt="HTTP://".$txt;
if (substr(strtoupper($txt),0,7)!="HTTP://";)
return 0;
eregi("^(http://([^/ ]+))",$txt,$arr);
return $arr[2];
}$remote_url = "http://www.domain.com/script.php";
// built up POST data
$request = "?name=Paul&greatness=high";// Build the header
$header = "POST $remote_url HTTP/1.0\r\n";
$header .= "Content-type: application/x-www-form-urlencoded\r\n";
$header .= "Content-length: " . strlen($request) . "\r\n\r\n";// Open the connection
$fp = fsockopen(servername($remote_url), 80);if ($fp) {
// Send HTTP request
fputs($fp, $header . $request);// Get the response
$response="";
while (!feof($fp))
$response .= fgets($fp, 128);fclose($fp);
print $response;
} else {
die ("Cannot connect!");
}
?>
Note: HTTP/1.1 requires an absolute URI as argument to Location
[php.net...]
The query string is a valid part of a URI and may therefor be used as a URI with the Location header.
Andreas