Hi.
I've came across with the problem as well and I wonder if you have the solution already ?
What I want to do is to invoke a php script from another server via http post with some variables passing to it. Let me show you my script, I'm using what sascha has written :
<?
filename: posttohost.php
function PostToHost($host, $path, $data)
{
$fp = fsockopen($host,80);
printf("Open!\n");
fputs($fp, "POST $path HTTP/1.1\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: ".strlen($data)."\n");
fputs($fp, "Connection: close\n\n");
fputs($fp, "$data");
printf("Sent!\n");
while(!feof($fp))
{
$res .= fgets($fp, 128);
}
printf("Done!\n");
fclose($fp);
return $res;
}
$data = "login=bbbear&var=abctesting";
printf("Go!\n");
$x = PostToHost("192.xxx.xx.xxx", "/home/path/to/the/script.php", $data); ?>
And here's the content of the script.php:
<?
//To create a new file with the data that passed from other server
srand((double)microtime()*1000000);
$file = rand();
$ar_var[0] = $login;
$ar_var[1] = $var;
$str = join($ar_var, ";");
$fp = fopen($file, "w");
fwrite($fp, $str, strlen($str));
fclose($fp);
?>
When I run the script "posttohost.php", the browser shows this line "Go! Open! Sent! Done!" but there's no new file being created on the server that I've given to the function. Have I missed anything ?
Anyway, is there any other alternatives that can be adopted for "server-to-server talk" kind of application ?
Thank you very much.