School of Computing. Dublin City University.
Online coding site: Ancient Brain
coders JavaScript worlds
I do the introduction to HTML Forms and server-side programs with PHP:
That is the best introduction to this topic. This page remains in case you do need a CGI solution.
<FORM METHOD="GET" ACTION="https://SERVER/cgi-bin/USER/PROGRAM"> <b> Enter argument: </b> <INPUT size=40 name=q id=q > <INPUT TYPE="submit" VALUE="Submit"> </FORM>
The input comes in as the environment variable QUERY_STRING.
If there is a single argument, QUERY_STRING will be of the form:
fieldname=actualargument
We need to edit it to remove the fieldname= bit at the front.
The CGI script builds a web page dynamically,
by outputting HTML tags to stdout.
In fact, the CGI script could output something other than a web page, e.g. an image.
It tells the client what is coming using the
Content-Type: HTTP header
and a
MIME type.
#!/bin/sh echo "Content-type: text/html" echo echo '<html> <head> <title> CGI script </title> </head> <body>' argument=`echo "$QUERY_STRING" | sed "s|q=||"` echo " QUERY_STRING is: <b> $QUERY_STRING </b> <br>" echo "Actual argument is: <b> $argument </b> <br>"
The same issues with
Security of user input
need to be taken care of.