kaancho12
Technical User
- Feb 22, 2005
- 191
hi,
ok, i have a cgi program which is supposed to take a xml file and go through it and return some string data. i dont know the variables of how the cgi program is executed.
But I need to upload a xml file to this program through php and i have been using curl to do this. When i try to execute php i get the error "premature end of script headers: db.cgi".
So, i tried to execute the program by going to the folder where the cgi program exists and giving it this command (it accepts two parameters):
perl db.cgi cApp=1 db=prod xmlfile.xml
But, i get the error:
Unrecognized character \x7F at db.cgi line 1.
Now, is there anything that I need to be doing to execute the cgi program at command prompt. Btw I am on a linux machine.
// Either 'http' or 'https'. 'https' is only an option if OpenSSH
// is available on your system. Check phpinfo() to see whether
// HTTPS is available.
$HTTP_method = 'http';
// IP-resolvable FQDN of the server
$hostname = 'localhost';
// Path on that server to the CGI
$cgi = '/cgi-bin/db.cgi';
// Array of data. The foreach loop below is going to construct a field/data
// string like the one you see in the URL of a GET-method CGI.
$my_data = array (
'cApp' => '1',
'db' => 'prod'
);
// This section constructs the field/value pairs of the form
// field1=value1&field2=value2&field3=value3
$data_string = " ";
$add_ampersand = FALSE;
foreach ($my_data as $key => $value)
{
if ($add_ampersand)
{
$data_string .= '&';
}
$data_string .= $key . '=' . $value;
$add_ampersand = TRUE;
}
//Set a file handle
$fp = file('/var/
// Get a CURL handle
$curl_handle = curl_init();
// Tell CURL the URL of the CGI
curl_setopt ($curl_handle, CURLOPT_URL, $HTTP_method . '://' . $hostname . $cgi);
// This section sets various options. See // for more details
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data_string);
curl_setopt ($curl_handle, CURLOPT_INFILE,$fp);
curl_setopt ($curl_handle, CURLOPT_USERPWD,"userasswd");
// Perform the POST and get the data returned by the server.
$result = curl_exec($curl_handle) or die ("There has been an error");
// Close the CURL handle
curl_close ($curl_handle);
ok, i have a cgi program which is supposed to take a xml file and go through it and return some string data. i dont know the variables of how the cgi program is executed.
But I need to upload a xml file to this program through php and i have been using curl to do this. When i try to execute php i get the error "premature end of script headers: db.cgi".
So, i tried to execute the program by going to the folder where the cgi program exists and giving it this command (it accepts two parameters):
perl db.cgi cApp=1 db=prod xmlfile.xml
But, i get the error:
Unrecognized character \x7F at db.cgi line 1.
Now, is there anything that I need to be doing to execute the cgi program at command prompt. Btw I am on a linux machine.
// Either 'http' or 'https'. 'https' is only an option if OpenSSH
// is available on your system. Check phpinfo() to see whether
// HTTPS is available.
$HTTP_method = 'http';
// IP-resolvable FQDN of the server
$hostname = 'localhost';
// Path on that server to the CGI
$cgi = '/cgi-bin/db.cgi';
// Array of data. The foreach loop below is going to construct a field/data
// string like the one you see in the URL of a GET-method CGI.
$my_data = array (
'cApp' => '1',
'db' => 'prod'
);
// This section constructs the field/value pairs of the form
// field1=value1&field2=value2&field3=value3
$data_string = " ";
$add_ampersand = FALSE;
foreach ($my_data as $key => $value)
{
if ($add_ampersand)
{
$data_string .= '&';
}
$data_string .= $key . '=' . $value;
$add_ampersand = TRUE;
}
//Set a file handle
$fp = file('/var/
// Get a CURL handle
$curl_handle = curl_init();
// Tell CURL the URL of the CGI
curl_setopt ($curl_handle, CURLOPT_URL, $HTTP_method . '://' . $hostname . $cgi);
// This section sets various options. See // for more details
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, 1);
curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data_string);
curl_setopt ($curl_handle, CURLOPT_INFILE,$fp);
curl_setopt ($curl_handle, CURLOPT_USERPWD,"userasswd");
// Perform the POST and get the data returned by the server.
$result = curl_exec($curl_handle) or die ("There has been an error");
// Close the CURL handle
curl_close ($curl_handle);