http://www.foo.com/cgi-bin/foo,
where foo is the name of the script or program, and
the /cgi-bin/ path is a special path that references
the directory containing the special programs and scripts that
can be executed by the server.
/u/www/Webdocs/Personnel on my
http server. I want to allow someone to search this file for
names, using a WWW browser, and I want to do this using the
ISINDEX element.
grep).
My script is srch-example,
found in my server's cgi-bin directory.
This is accessed via the URLhttp://www.utirc.utoronto.ca/cgi-bin/srch-example.
Here is the content of srch-example:
#!/bin/sh echo Content-type: text/html echo if [ $# = 0 ] then echo "<HEAD>" echo "<TITLE>UTIRC Phonebook Search</TITLE>" echo "<ISINDEX>" echo "</HEAD>" echo "<BODY>" echo "<H1>UTIRC Phonebook Search</H1>" echo "Enter your search in the search field.<P>" echo "This is a case-insensitive substring search: thus" echo "searching for 'ian' will find 'Ian' and Adriana'." echo "</BODY>" else echo "<HEAD>" echo "<TITLE>Result of search for \"$*\".</TITLE>" echo "</HEAD>" echo "<BODY>" echo "<H1>Result of search for \"$*\".</H1>" echo "<PRE>" grep -i "$*" /u/www/Webdocs/Personnel echo "</PRE>" echo "</BODY>" fi
http://www.utirc.utoronto.ca/cgi-bin/srch-exampleWhat happens? When the script is accessed it always echoes the line
Content-type: text/html. This is sent
back to the browser, so that the echoed material becomes
the new document. In particular this line tells the browser to
expect a text/html document.
the if statement checks to see if there are
any arguments to the script. Arguments are passed from the
browser to the server script via the URL: arguments to be passed
to the script are added to the end of the URL, separeted from the
regular URL by a question mark.
In our case there are no arguments so we execute the first branch
of the if. This echoes some standard HTML definitions,
and then sends the ISINDEX code. This tells the browser that
this is a search.
The browser display the received document and prompts you for a search string. For example, Mosaic will present a fill-in template, where you type the desired search string. When you press return, the browser accesses the same URL as before, but now appends the appropriate search string. For example, if I filled in the form with my name (Ian) the accessed URL is now
http://www.utirc.utoronto.ca/cgi-bin/srch-example?ian
The above URL again accesses srch-example,
but this time with an argument (Ian), so that the second branch
of the if is executed. This branch
echoes new headings, indicating what was searched for,
and runs the grep program to search the file.
By default the output of grep is echoed, so the
search results are sent to the browser. ISINDEX is NOT
added here, as this branch provides the results of the search.
The final result is a document containing the search results.