C++ Programming As A Set Of Problems/CGI Script program

simple script
Compile this source code into an executable named "test_script.cgi".

setup
Nearly all web servers support the Common Gateway Interface. Here is some brief notes on how to put a CGI script written in C++ on an Apache server; other web servers are similar. For more details, see the Apache wikibook, section ..., or the analogous documentation for your favorite web server.

... security implications: user "nobody" ...

CGI scripts are used to deal with form data submission. Here is an example HTML file that lets the user submit data to a "test_script.cgi" program.

Put the compiled "test_script.cgi" in the appropriate "cgi-bin" directory. Put the "test_form.html" in some convenient location -- typically some other directory on the same server, but it also works if it's on some other server or a file on your local machine. Tweak the "action" property to give a path to the CGI script.

testing
Fire up your favorite web browser, and point it at the "test_form.html". Click the submit button. The output from the CGI script should be displayed. Click the "Valid" link.

static HTML
The above script always gives the same output -- if that's really what you want, then a simple static HTML page would give the same results for less effort:

The power of CGI scripts is in doing things that are not possible with a static HTML page.

getting input to the script
There are several libraries already available to handle the tricky bits of splitting the CGI input into a list of name/val pairs.


 * getcgivars.c from http://www.jmarshall.com/easy/cgi/getcgi.c.txt
 * ... other CGI libraries in C and C++ ...

A CGI script doesn't use the command-line arguments "argc" or argv". Instead, it gets its input from environment variables -- and, in the case of HTTP PUT or HTTP POST, the program reads user-submitted data from the standard input.

Compile this source code into an executable named "test_script.cgi". Use the same test_form.html to test it.