For this lab, we will write a simple cgi application. CGI handlers are usually written in Perl, but you should write yours in C, because perl hides too much.
You should write a simple html form which looks like this.
If you are rusty on the syntax of html forms, take a look at
this website.
http://www.w3schools.com/html/html_forms.asp
Write a cgi script in C or C++ which reads the data and prints a screen that looks like this.
Thanks Suzy Creamcheese, your comments have been sent to the CSCI dept.
replacing the strings in italics with the values entered on the form.
To run it,
put it in a directory ~yourname/public.html
, making sure
that it is executable by the user and the world.
You should use the POST method.
All the heavy lifting is done for you if you include the file
http://www.cs.rpi.edu/~ingallsr/cgi.h
,.
This contains a function void parseline(char *s), which takes a null terminated string as
an argument and parses it. It creates two global variables, int count and
char vars[][][], and fills in values. The variable count contains the number of variable/value
pairs, and the variable vars contains these pairs. If the first variable is
lastname, the second variable is firstname, and the user's name was
Suzy Creamcheese, vars would look like this
vars[0][0] | lastname |
vars[0][1] | Creamcheese |
vars[1][0] | firstname |
vars[1][1] | Suzy |
Once you have this working using the POST method, redo your program so that it uses the GET method. Recall that with the GET method, the string is in the environment variable QUERY_STRING. There is c function char *getenv(char *s) which returns the value of the environment variable with the name s.