Example of a WWW interface



What do I have to do to make it work ?

1) Create an HTML form that will take input from the user. View the "document source" to see how this form was constructed. Note the defining statement:
< FORM method=POST action="/cgi-bin/answer" target=answer>
The POST method is specified with action passed to a shell script "answer" kept in a special CGI binary directory /cgi-bin/ Note that output is re-directed to a new target page called "answer". An "input" box of type "submit" to hold parameter "Ask" is defined:
< input name=question size=31 maxlength=100 value="???">
< INPUT TYPE="submit" VALUE="Ask">

2) Create a shell script "/cgi-bin/answer" that will interpret the input, run your program with this input, and return the result as an HTML document. Note that any such executable scripts or other programs (called CGI) MUST reside in this special "cgi-bin" directory (for which you need special privileges to access). The script looks like this:

#!/bin/sh
PATH=.:/bin
echo "Content-type: text/html"
echo 
read input 	
query=`echo $input | sed 's/+/ /g' | sed 's/%3F/?/g' ` 
echo "You asked me: "$query
/w3/HTTPD_SERVER/cgi-bin/fortrantime 
Note that first we defined the PATH system variable (to make sure the system can find commands), and then echoed the plain text mime-type plus a blank line. The line starting "query=" is a bit of Unix SED jargon to replace all "+" by " " and all "%3F" by "?". These (and other) special characters are automatically substituted by the POST form. We echo the resulting variable $query just to show that it has been understood.

Finally, we run the compiled fortran program fortrantime, which is also kept in /cgi-bin/. It might use $input or $query (but does not); it simply writes the system time to the output stream, which was pointed to the new WWW target page "answer". OK, now try it.

Of course you can also run the program fortrantime without input by simply pointing to it from your browser. Then try hitting "reload" to check that the program is really re-run to update the time.

Good luck Garry !