FIT3084: Forms
& CGI
In the previous lecture:
In this lecture:
- Enables applications to persist between client requests, eliminating application start up overhead and allowing the application to maintain state between client calls.
- Enables applications to reside on remote systems (rather than having to reside on the same system as the Web server)
The counter is accessed like this: <img src="/cgi-bin/Count.cgi?dd=A&df=aland_lect17_page.dat&ft=0&srgb=white&prgb=red" align=absmiddle> This is a typical access to a CGI script. You can read about the details of the counter online. |
In your own time: |
Have a look at the interface to the Altavista search engine. Look at a query in the browser's URL entry box. |
Here's some of the HTML...
<FORM ACTION="/cgi-bin/order_toys" METHOD=POST >
<P>Secret Agent Name:
< INPUT TYPE="text" NAME="name">...
<INPUT TYPE="submit" VALUE="Transmit Order to HQ">
< INPUT TYPE="reset" VALUE="Eat Order">
< /FORM>
main(int argc, char **argv) { printf("Content-type: text/html\n"); // tell server MIME type of returned doc. printf("\n"); // blank line printf("<HEAD><TITLE><BR>\n'); // output HTML header info. printf("Echo Script Response<BR>\n"); printf("</TITLE></HEAD><BR>\n"); printf("<BODY>\n<P>\n"); // output HTML body echoing the printf("%s", getenv("QUERY_STRING"));// environment variable QUERY_STRING printf("</BODY>\n"); }
Let's call the same script again (from the same form) but this time, the ACTION attribute of the FORM tag will call the script via cgi-wrapd...
An additional note for completeness... Parameters can be read into a C program where the form applies the POST method, like this (see the Stanford site from which this info. originates for details): "The POST query string is encoded in precisely the same form as the GET query string, but instead of being passed in the URL and read into the QUERY_STRING variable, it is given to the CGI program as standard input, which you can thus read using ANSI functions or regular character reading functions. The only quirk is that the server will not send EOF at the end of the data. Instead, the size of the string is passed in the environment variable CONTENT_LENGTH, which can be accessed using the normal stdlib.h function:"
|
The Content Type Field
The Location Field
©Copyright Alan Dorin 2009