Example 7.4 | CGI-based image selection



This is an example of an image which has been selected and returned by a CGI program.

When this HTML file is loaded, the web browser will then re-connect to the web server to get any files [graphics, etc] which are mentioned in the HTML data. In this case, specifically, the browser will reconnect to the server to get the image file "example.7.4.cgi"... which the web server will recognize as a CGI file and execute.

Our example.7.4.cgi script will then return the correct Content-Type, in this case image/gif, and return the data, which will be displayed in it's correct location.

Since the CGI script which output this image will always output the same image, this is useful for demonstration purposes only. But the principle is very useful, as data can be passed following a '?' in the <IMG SRC="cgiprog.cgi?<extra data>" ....> line, which allows one to specify whatever one wants to make the script more useful.

An example of this is randomized image selection; the CGI program can be passed the name of a directory from which to randomly choose an image, and will do so. See getinfo.cgi for an example of this. As well, a product ID number could be passed, which would allow the CGI script to get the correct graphic from a database or other source associated with the product ID.

example.7.4.cgi source
print-source.cgi source


Ladies and Gentlemen... the lovely Janeane Garofalo!

[A CGI-generated image]