Hey man, was a having the same problem a couple of weeks ago. Nobody seemed to know what I was going on about, so I just sat down and worked it out myself. (Yeah who would thought of doing that?? lol)
K, like you say, Clients can POST data to the server using HTML forms.
But, to POST data from one server to another you need send the appropriate Headers with the data telling it to be posted as form-encoded data.
Here's how:
function HTTPPost($sPostURL){
foreach($_POST as $key => $value){
$sPostVars .= "$key=" . urlencode($value) . "&";
}
$sPostVars = substr($sPostVars, 0, -1);
$header .= "POST $sPostURL HTTP/1.0\r\n";
$header .= "Accept: */*\r\n";
$header .= "Accept-Language: en-au\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= 'Content-Length: ' . strlen($sPostVars) . "\r\n\r\n";
$fp = fsockopen("localhost", 80, $errno, $errstr, 30);
if(!$fp)
echo "$errstr ($errno)";
else{
fputs($fp, $header . $sPostVars);
while(!feof($fp))
$res .= fgets($fp, 1024);
fclose($fp);
}
preg_match("/<!DOCTYPE.*/s", $res, $aMatches);
echo $aMatches[0];
exit;
}
Ok. The first thing we do here is get all the data we wish to POST to the server. In this case I'm using data from a previous form in the $_POST array. I put it all into $sPostVars;
Then we set up the Header to tell the server that we're sending URL encoded data via POST.
Next you make a socket connection to the server, and then use fputs to transfer the data to the server.
Next you have to read the data that the server sends back in reply. (which is the 'while' loop)
Lastly I use preg_replace to cut out all the crap that get's sent back. For some reason it sends back some weird data before the actual HTML. (This is on my server anyway. Don't know if it will do this for you - I just cut it out.)
Play around anyway. Should be fun. hehe.
cya
-Adam 🙂