The real danger is not that computers will begin to think like men, but that men will begin to think like computers -- Sydney J. Harris

Tute #4 - Forms and CGI

  1. A HTML form can be written to submit data using either the GET or POST method. Describe how the form data is submitted to the web server in each of these cases. Detailed answer required.

  2. Why is submitted form data URL-encoded? Explain why it's necessary, and discuss what could happen if it wasn't encoded.

  3. In the lecture, the comment was made that a CGI program could be (relatively) easily written to accomodate either the GET or POST request methods. Discuss reasons why you might wish to do this. Make sure you understand the issues here!

  4. Is it possible that a browser could send information to a CGI using (effectively) both GET and POST at the same time? In other words, is it conceivable that the URL could be of the form used in the usual GET request (ie. data appended after a ?), and additionally have a request body containing the POST data? Discuss.

  5. Hard question: in a popular (but unnamed) text on CGI programming, the following lines of Perl are suggested for decoding a URL encoded string:

    $info =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $info =~ s/\+/ /g;
    @fields = split (/&/, $info);
    ... etc ...
    

    There is a serious problem with the order of execution in this code. What is it? Explain carefully.

  6. Research[1]: look up your Perl reference (whichever one you have chosen to use) and carefully figure out what the following line of code is actually doing (we'll be using it in the next lecture!):

    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    

    It's actually not so difficult!

  7. Research: find out about how the the PATH_INFO and PATH_TRANSLATED variables are used.

[1] You are not expected to answer these two questions in the tutorial time.