Hi Guys.
I had asked for help with the basic part of this a while back.
I got it working then immediately a recent server migration broke
it by disallowing remote connection.
Here is the solution for that too, all in one place.
Here is how to send a "fake" post into a script whether or not remote
connection is disallowed.
You will be able to tell by the returned text which method it ended up
having to use.
Notice that the + is replaced to prevent the ArgV[0] from ending at the
first +. That is what it
takes to get the whole post over to the target script intact.
Here is the routine to send the post:
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function SendPost($host, $path, $data, $DoArg){
if ($DoArg){
$ArgVzero = str_replace("+", "!~plus~!",
urlencode(stripslashes($data)));
$res = file_get_contents("http://$host$path"."?".$ArgVzero);
}
else{
$header .= "POST http://$host$path HTTP/1.1\r\n";
$header .= "Host:$host\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($data) . "\r\n";
$header .= "Connection: Keep-Alive\r\n\r\n";
$fp = fsockopen ($host, 80, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
$res="error";
} else {
fputs ($fp, $header);
fputs ($fp, $data);
while (!feof($fp)) {
$res .= fgets ($fp, 1024);
} // (end while)
fclose ($fp);
} // (end if)
if ($res ==""){
//It did not allow to post; therefore hit it with an ARG
$ArgVzero = str_replace("+", "!~plus~!",
urlencode(stripslashes($data)));
$res = file_get_contents("http://$host$path"."?".$ArgVzero);
}
}
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
And here is the code to insert at the top of your php code that receives
the post:
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$ArgVzero = $argv[0];
if ($ArgVzero <> ""){
$ArgVzero = str_replace("!~plus~!", "+", $ArgVzero);
$ArgVzero = urldecode($ArgVzero);
$ArgVzero .= "&ArgHit=true";
parse_str($ArgVzero, $_POST);
echo "HTTP/1.1 ARG OK Date: ".date("F j, Y, g:i a")." GMT Server
Connection: File_Get_Contents using ?argv[0] arguments \r\n";
}
// All Done! Now your script will work even with a "fake posted" hit.
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hope it helps someone. It was the only way I survived a migration to a
new server.
Best Regards,
Robison