| I have a little problem with my ksh shell/CGI.
| It should get the variable "QUERY_STRING" from HTML file, which is empty and
| my script doesn't work correctly.
| 
| [HTML]
| <form action="http://XXXXXXX/cgi-bin/unix/search_XXXXXXXXX.cgi"
| method="POST">
| ------- valore 1 <input name="param1" size="50"> <input type="submit"
| value="Submit">
| </form>

$QUERY_STRING is only set for "GET" type forms, not "POST"s.
With GET, the browser sends a request like this:

    GET http://XXXXXXX/cgi-bin/unix/search_XXXXXXXXX.cgi?param1=foo&submit=Submit 
HTTP/1.0
    Host: XXXXXXX

and a few other headers. With POST, the browser sends a request like this:

    POST http://XXXXXXX/cgi-bin/unix/search_XXXXXXXXX.cgi HTTP/1.0
    Host: XXXXXXX
    Content-Type: form/url-encoded

    param1=foo
    submit=Submit

For the first version, the CGI script received the query via the
$QUERY_STRING variable as "param1=foo&submit=Submit", which it then
parses and handles. For the second version ,the CGI script receives the
query on its standard input, which it can parse like this:

        while read param
        do  eval "PARAM_$param"
        done

As with QUERY_STRING, the values are url encoded and must have their %xx
parts translated back into characters. The above code does not do that.

Personally, I _much_ prefer to use GET instead of POST. It has the
advantage that the user can bookmark the result of the form submission.
(For example, it is common and useful to bookmark the result of a web
search.) You can't do that with POSTs. You only really need posts when
you're submitting significant amounts of data, such as TEXTAREA fields
or uploading files.

You can examine the headers supplied with the request and the request
type (GET or POST) by looking at environment variables.

As an example, visit:

        http://cgi.zipworld.com.au/cs/debug.cgi?param1=foo

which is my CGI debug script. You can see its working directory,
who it runs as, its arguments, and the entire environment. All
the headers are available in the HTTP_* variables, etc.

You can also set up a form with:

        http://cgi.zipworld.com.au/cs/debug.cgi

as its action to text things.

Cheers,
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Reason #173 to fear technology:

    o       o       o       o       o       o      <o      <o>
   ^|\     ^|^     v|^     v|v     |/v     |X|      \|      |
    /\      >\     /<       >\     /<       >\     /<       >\

    o>      o       o       o       o       o       o       o
    \       x      </      <|>     </>     <\>     <)>      |\
   /<       >\     /<       >\     /<       >\      >>      L

             Mr. email does the Macarena.



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to