Solved

Environment variables to CGI executables

Posted on 1997-10-13
4
300 Views
Last Modified: 2013-12-25
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-urlencoded<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>
0
Comment
Question by:wrobel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1830793
When REQUEST_METHOD is POST, QUERY_STRING is instead passed as CONTENT_LENGTH bytes from stdin
0
 
LVL 7

Accepted Solution

by:
faster earned 150 total points
ID: 1830794
ozo is correct, you can see that there is a line that reads:

REQUEST_METHOD is: POST<BR>

So you are using "POST" in the form.  You have two options:

1) modify the html that contains the form to change METHOD from "post" to "get".

2) use post method, then your cgi program should do the following: read env variable CONTENT_LENGTH, then read that much bytes from stdin.  What you will get is the same as "QUERY_STRING" in 1)

After you can that string, it will be in the form as "var1=value1&var2=value2...", you need to parse it and do the url unescaping (change '+' to ' ' and %xx to ascii value.

The rest should be simple,  just remember to include the "Content-type: text/html\r\n\r\n" line in your output
0
 

Author Comment

by:wrobel
ID: 1830795
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
0
 
LVL 2

Expert Comment

by:dmethvin
ID: 1830796
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;
  }

}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question