Here is a corrected version.
It works on many newer servers without having to resort to the ARG method.
The difference is that the newer servers seem to accept a post to a
relative address from $host rather than an absolute url.
With that one change it now works on my vdeck 3.0 server without having
to use the ARG method. That means that the
post data size is no longer limited by the max url length. (yay!)
Here is the corrected version:
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 $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.
Best Regards,
Robison