Quoting Russ Goodwin ([EMAIL PROTECTED]):
> Hi all-
>
> Has anyone else done this successfully? What method did you use for
> calling the cgis?
>
This snippet may help you. I used this to call some cc processing
scripts from PHP. The output of the script is sent back to the
browser untouched. It deals with sending cookies to and from the
browser and will handle PHP style array parameters.
<?
if ($REQUEST_METHOD == "POST")
$values = $HTTP_POST_VARS;
else if ($REQUEST_METHOD == "GET")
$values = $HTTP_GET_VARS;
else
exit;
$parameters = "";
$machine = "www.somemachine.com";
$port = 80;
$errno = 0;
$error_string = "";
$proc = "/cgi-bin/someprogram";
while (list ($key, $val) = each ($values))
{
if (is_array($val))
{
while (list($k1, $v1) = each($val))
{
$v1 = urldecode($v1);
if ($parameters != "")
$parameters .= "&";
$parameters .= "<input type=\"hidden\" name=\"$key" . "[]\" value=\"" .
urlencode($v1) . "\">\n";
}
}
else
{
$val = urldecode($val);
if ($parameters != "")
$parameters .= "&";
$parameters .= "<input type=\"hidden\" name=\"$key\" value=\"" .
urlencode($val) . "\">\n";
}
}
$fp = fsockopen("$machine", $port, &$errno, &$error_string);
fputs($fp, "POST $proc HTTP/1.0\r\n");
while ($x = each($HTTP_COOKIE_VARS))
fputs($fp, "Cookie: $x[0]=$x[1]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, sprintf("Content-length: %d\r\n\r\n", strlen($parameters)));
fputs($fp, $parameters);
$in_body = 0;
while(!feof($fp))
{
$line = fgets($fp, 512);
if ($line == "\r\n")
$in_body = 1;
else if ($in_body)
print "$line";
else if (eregi("^set-cookie", $line))
header(trim($line));
}
fclose($fp);
?>
> - Using exec or ``: $result = `$cmd $args`; Here we converted the POSTed
> variables onto the arg list, but PHP doesn't like the multiple "domain"
> fields it's sent - it just picks the last one.
The field name on the form needs to be an array rather than just
repeating the field name more than once:
name=domain[]
Hope this helps. No warranty available.
John Capo
IRBS Engineering, Inc.