Kaye and Geoff's web page documentation 

The CGI to write to the guestbook with acknowledgement

The guestbook is made up of three files containing HTML code - a header, a body which has the entries, and a footer. This structure means that this script can just append to the body file without having to carry out complex insertions. A more sophisticated guestbook might allow the owner to delete arbitary records and and archive old records; in practice it will also be necessary to check for antisocial entries of various sorts, for example rude or abusive words and HTML code which may include active links or scripts.

#!/usr/bin/perl # # writes information to a guestbook # resub restores escaped characters # require 'Resub.pm'; # # get the date and time and information about the contributor # $date = `date`; $host = $ENV{'REMOTE_ADDR'}; # # get the information from the form # convert escaped characters # set any missing fields to a default value # replace newline and other white space characters # $incoming = <STDIN>; foreach $item (split(/&/,$incoming)) { ($var,$value) = split(/=/,$item); $value = &resub ($value); if (!($value =~ /\S/)) { $value = '<br>'; } ($value = $value) =~ s/\s/ /g; if ($var eq "name") { $name = $value; } if ($var eq "country") { $country = $value; } if ($var eq "org") { $org = $value; } if ($var eq "comments") { $comments = $value; } } # # append this record to the guestbook # each record is one row in an HTML table # if (open (LOG, ">>guestbook")) { print LOG "<tr><td>$date<\/td>"; print LOG "<td>$name<\/td>"; print LOG "<td>$country<\/td>"; print LOG "<td>$org<\/td>"; print LOG "<td>$comments<\/td><\/tr> \n"; close (LOG); } # # display a confirmation page # print "Content-type: text/html\n\n"; print '<html><head><title>Guestbook</title></head>'; print '<body bgcolor="#ffffff">'; print "\n"; print '<br><br><b>Thank you for adding your comments to our guestbook</b>'; print '<p>Your comments have been noted'; print "\n"; print '<form action="http://www.kgweb.org.au/cgi-bin/docs/cgi_read.pl method="post">'; print "\n"; print '<input type="submit" value="View the guestbook">'; print '</form>'; print "\n"; print '</body></html>'; exit;
Top
Close