Guest Books

A guest books allows a visitor to your site to add a formatted comment to a list of comments in a web page that is in your site.

The guestbook CGI script is triggered by a form very much like the eform.cgi script that we covered in class. It uses the following magic variables:

Note that the names of these inputs must be in all uppercase, as shown.

Note also that the filenames must be complete absolute pathnames, so, for example:

<input type="hidden" name="FILE" value="/students/wwellesl/public_html/guestbook-entry.html">

The guestbook file needs to have a special comment in it that is exactly the following:

<!--- APPEND HERE --->
The comment has to be exactly that, because the CGI script looks for that exact bit of HTML and puts the new entry right there. If you add or remove a single hyphen, it won't work. Also, the comment must be exactly at the beginning of the line (don't indent even one space) in order to be found.

Finally, you have to make the guestbook file world-writable. You can do that using an FTP client. Using "Fetch," for example, select the guestbook file, then click on the "Get Info" icon (or "Remote / Get Info") and, then, under "Ownership and Permissions" check the "write" boxes for owner, group, and others. (The fine print says that the equivalent UNIX command is "666".)

The CGI script automatically puts the time of the entry at the beginning of the entry.

Here's an example:

Note that in this example, I've separated the form for adding entries from the guestbook, but that's not required. There's no reason that the guestbook couldn't have the entry form at the top of it.

Written by Scott D. Anderson
scott.anderson@acm.org
Creative Commons License
This work is licensed under a Creative Commons License.