wrobel
asked on
Environment variables to CGI executables
Dear Sir/Madam,
Thanks for helping, I'm completly stuck.
I'm trying to setup a Web search engine on a NT 4.0
server.
I'm calling /scripts/cgi.exe, that I wrote in 'C'
as an ACTION of a html FORM statememt.
The FORM statememt has two INPUT TYPE=TEXT and one
INPUT TYPE=RADIO sections.
Chapter 8 of the help for Microsofts Internet
Explorer says the following environment variables
are setup. However as you can see from the list
below, some are not. In particular the QUERY_STRING
is not setup, its the QUERY_STRING I particualy want
to get hold of. Any idears?
Also when I manage to access the QUERY_STRING will
it need further parsing? Is there someting that Microsoft
ship for NT 4.0 Server that does the parsing for you?
Thanks for any help you can give.
Allan.
cairs-support@cairs.co.uk
ALL_HTTP is: NULL<BR>
AUTH_TYPE is: NULL<BR>
CONTENT_LENGTH is: 30<BR>
CONTENT_TYPE is: application/x-www-form-url encoded<BR >
GATEWAY_INTERFACE is: CGI/1.1<BR>
HTTP_ACCEPT is: image/gif, image/x-xbitmap, image/jpeg, */*<BR>
LOGON_USER is: NULL<BR>
PATH_INFO is: NULL<BR>
PATH_TRANSLATED is: C:\InetPub\wwwroot<BR>
QUERY_STRING is: NULL<BR>
REMOTE_ADDR is: 193.132.193.176<BR>
REMOTE_HOST is: 193.132.193.176<BR>
REMOTE_USER is: NULL<BR>
REQUEST_METHOD is: POST<BR>
SCRIPT_NAME is: /scripts/cgi.exe<BR>
SERVER_NAME is: 193.132.193.176<BR>
SERVER_PORT is: 80<BR>
SERVER_PORT_SECURE is: 0<BR>
SERVER_PROTOCOL is: HTTP/1.0<BR>
SERVER_SOFTWARE is: Microsoft-IIS/2.0<BR>
URL is: NULL<BR>
Thanks for helping, I'm completly stuck.
I'm trying to setup a Web search engine on a NT 4.0
server.
I'm calling /scripts/cgi.exe, that I wrote in 'C'
as an ACTION of a html FORM statememt.
The FORM statememt has two INPUT TYPE=TEXT and one
INPUT TYPE=RADIO sections.
Chapter 8 of the help for Microsofts Internet
Explorer says the following environment variables
are setup. However as you can see from the list
below, some are not. In particular the QUERY_STRING
is not setup, its the QUERY_STRING I particualy want
to get hold of. Any idears?
Also when I manage to access the QUERY_STRING will
it need further parsing? Is there someting that Microsoft
ship for NT 4.0 Server that does the parsing for you?
Thanks for any help you can give.
Allan.
cairs-support@cairs.co.uk
ALL_HTTP is: NULL<BR>
AUTH_TYPE is: NULL<BR>
CONTENT_LENGTH is: 30<BR>
CONTENT_TYPE is: application/x-www-form-url
GATEWAY_INTERFACE is: CGI/1.1<BR>
HTTP_ACCEPT is: image/gif, image/x-xbitmap, image/jpeg, */*<BR>
LOGON_USER is: NULL<BR>
PATH_INFO is: NULL<BR>
PATH_TRANSLATED is: C:\InetPub\wwwroot<BR>
QUERY_STRING is: NULL<BR>
REMOTE_ADDR is: 193.132.193.176<BR>
REMOTE_HOST is: 193.132.193.176<BR>
REMOTE_USER is: NULL<BR>
REQUEST_METHOD is: POST<BR>
SCRIPT_NAME is: /scripts/cgi.exe<BR>
SERVER_NAME is: 193.132.193.176<BR>
SERVER_PORT is: 80<BR>
SERVER_PORT_SECURE is: 0<BR>
SERVER_PROTOCOL is: HTTP/1.0<BR>
SERVER_SOFTWARE is: Microsoft-IIS/2.0<BR>
URL is: NULL<BR>
When REQUEST_METHOD is POST, QUERY_STRING is instead passed as CONTENT_LENGTH bytes from stdin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear Faster,
Thanks. Is there any product that will do
the parsing for me? I Don't want to re-invent
the wheel.
Yours
Allan
cairs-support@cairs.co.uk
Thanks. Is there any product that will do
the parsing for me? I Don't want to re-invent
the wheel.
Yours
Allan
cairs-support@cairs.co.uk
If you want something that's robust and handles all possible cases, use the CGI or CGI_Lite modules in CPAN at www.perl.com. My preference is just to use this piece of code, which handles all the cases I care about. At the end the variable %FORM has the form entries:
sub parse_form {
my $len = $ENV{CONTENT_LENGTH} || 0;
my $buffer = '';
if ( $len > 0 ) { # POST
read(STDIN, $buffer, $len);
} else { # GET
$buffer = $ENV{QUERY_STRING} || '';
}
# Split name-value pairs
foreach ( split(/&/, $buffer) ) {
my ($name, $value) = split(/=/);
# Remove URL encoding and HTML comments
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9] )/pack("C" , hex($1))/eg;
$value =~ s/<!--.*?-->//gs;
$FORM{$name} = $value;
}
}
sub parse_form {
my $len = $ENV{CONTENT_LENGTH} || 0;
my $buffer = '';
if ( $len > 0 ) { # POST
read(STDIN, $buffer, $len);
} else { # GET
$buffer = $ENV{QUERY_STRING} || '';
}
# Split name-value pairs
foreach ( split(/&/, $buffer) ) {
my ($name, $value) = split(/=/);
# Remove URL encoding and HTML comments
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9]
$value =~ s/<!--.*?-->//gs;
$FORM{$name} = $value;
}
}