E-Guest consists of three files:
E-Guest_sign.cgi:
-----------------
#!F:/Savant/perl5/bin/perl
$data = 'http://denniz.dyns.net:80
$title = 'Puszels Guestbook'; # page title
$bgcolor = '3C507D'; # background color
$display = '10'; # default # of entries to display per page
$fsize = '2'; # font size
$fface = 'Arial'; # font face
$fcolor = '000000'; # font color
$alink = '003388'; # link color
$avisited = '003388'; # visited link color
$ahover = '2255AA'; # hover link color
$twidth = '550'; # table width
$talign = 'center'; # table align (left/right/center)
$tborder = '1'; # table border size
$tbcolor = '000000'; # table orbder color
$tpadding = '5'; # table padding size
$tspacing = '5'; # table spacing size
$tcolor1 = 'dddddd'; # table color 1
$tcolor2 = '999999'; # table color 2
#=========================
# NO EDITING AFTER THIS LINE
#=========================
#=========================
# Get Form Fields Values
#-------------------------
# To get the values of the fields.
# Assign variables for each of the field's
# value.
#=========================
if ($ENV{"REQUEST_METHOD"} eq 'GET') {
$buffer = $ENV{'QUERY_STRING'};
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9]
$FORM{$name} = $value;
}
$fullname = $FORM{'fullname'};
$email = $FORM{'email'};
$homepage = $FORM{'homepage'};
$uin = $FORM{'uin'};
$location = $FORM{'location'};
$comment = $FORM{'comment'};
$action = $FORM{'action'};
#=========================
# Check and Fix Homepage Content
#-------------------------
# To check if the user input homepage value
# and if user input "http://" at the
# beginning of the string or not,
# if not, add the "http://" to fix it.
#=========================
if ($homepage && $homepage =~ /^http:\/\//){
$homepage = "$homepage";
} elsif ($homepage) {
$homepage = "http://$homepage";
}
#=========================
# Construct Date String
#-------------------------
# Standard construction for the date and
# time variable.
#=========================
@days = ('Sunday','Monday','Tuesda
@months = ('January','Feburary','Mar
'October','November','Dece
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime(time);
if($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
$saveyear = ($year % 100);
$year = 1900 + $year;
$date = "$days[$wday], $months[$mon] $mday, $year";
#=========================
# Check for Required Fields
#-------------------------
# Checking for the values for Full name, Email
# and Comment. If it's empty, add warning
# message in the variable $msg. Check for
# value UIN, homepage and email address format.
#=========================
if ($action eq add && $fullname eq '') {
$msg .= "Please fill in the \"Full name\" field!<br>";
}
if ($action eq add && $email eq '') {
$msg .= "Please fill in the \"Email\" field!<br>";
}
if ($action eq add && $comment eq '') {
$msg .= "Please fill in the \"Comment\" field!<br>";
}
if ($action ne add || $email eq '' || $email =~ /\@/i) {
} else {
$msg .= "Invalid address in \"Email\" field!<br>";
$format = Bad;
}
if ($action ne add || $homepage eq '' || $homepage =~ /\./i) {
} else {
$msg .= "Invalid address in \"Homepage\" field!<br>";
$format = Bad;
}
if ($action eq add && $uin ne '' && $uin =~ /[A-Z]/i) {
$msg .= "Invalid address in \"UIN\" field!<br>";
$format = Bad;
}
#=========================
# Print Page Header
#-------------------------
# This is the coding for the heading of
# the page.
#=========================
print "Content-Type: text/html\n\n";
print qq~
<!-- E-Guest guestbook system 1.1 -->
<!-- powered by leungeric.com -->
<html><head><title>$title<
<style>
A:link {text-decoration: none; color: #$alink}
A:visited {text-decoration: none; color: #$avisited}
A:hover {text-decoration: underline; color: #$ahover}
</style>
<body bgcolor=#$bgcolor>
<table width=$twidth bgcolor=#$tcolor2 align=$talign cellpadding=$tpadding cellspacing=$tspacing border=$tborder bordercolor=#$tbcolor>
<tr bgcolor=#$tcolor1 align=center>
<td>
<font face=$fface color=$fcolor><b>$title
<p align=right><font size=1>powered by <a href=http://leungeric.com target=_blank>leungeric.co
</td>
</tr>
</table>
<p>
<table width=$twidth bgcolor=#$tcolor2 align=$talign cellpadding=$tpadding cellspacing=$tspacing border=$tborder bordercolor=#$tbcolor>
<tr bgcolor=#$tcolor1>
<td colspan=2 align=center>
<font size=$fsize face=$fface color=$fcolor>
<b><a href=E-Guest_show.cgi>View
</td>
</tr>
<tr></tr><tr></tr>
~;
#=========================
# Check and Display Warning Message
#-------------------------
# If the required fields are missing,
# display the warning message in order to
# submit the entry.
#=========================
if ($msg) {
print qq~
<tr bgcolor=#$tcolor1>
<td colspan=2><font size=$fsize face=$fface color=#ff0000>$msg</td>
</tr>
<tr></tr><tr></tr>
~;
}
#=========================
# Displaying Sign Form
#-------------------------
# Display the signning form if all required
# fields are empty.
#=========================
if ($fullname eq '' || $email eq '' || $comment eq '' || $format eq Bad) {
print qq~
<form action="E-Guest_sign.cgi" method=post>
<tr bgcolor=#$tcolor1>
<td><font size=$fsize face=$fface color=$fcolor>Full Name :</td>
<td><input type=text name="fullname" value="$fullname" style="font-family: Arial; font-size: 10pt"> <font color=#$alink><b>*</b></td
</tr>
<tr bgcolor=#$tcolor1>
<td><font size=$fsize face=$fface color=$fcolor>Email :</td>
<td><input type=text name="email" value="$email" style="font-family: Arial; font-size: 10pt"> <font color=#$alink><b>*</b> <font color=#$alink><b>#</b></td
</tr>
<tr bgcolor=#$tcolor1>
<td><font size=$fsize face=$fface color=$fcolor>Homepage :</td>
<td><input type=text name="homepage" value="$homepage" style="font-family: Arial; font-size: 10pt"> <font color=#$alink><b>#</b></td
</tr>
<tr bgcolor=#$tcolor1>
<td><font size=$fsize face=$fface color=$fcolor>UIN :</td>
<td><input type=text name="uin" value="$uin" style="font-family: Arial; font-size: 10pt"> <font color=#$alink><b>#</b></td
</tr>
<tr bgcolor=#$tcolor1>
<td><font size=$fsize face=$fface color=$fcolor>Location :</td>
<td><input type=text name="location" value="$location" style="font-family: Arial; font-size: 10pt"></td>
</tr>
<tr bgcolor=#$tcolor1>
<td><font size=$fsize face=$fface color=$fcolor>Comment :</td>
<td>
<textarea name="comment" cols=47 rows=5 wrap=on style="font-family: Arial; font-size: 10pt">$comment</textarea> <font color=#$alink><b>*</b> <font color=#$alink><b>!</b>
</td>
</tr>
<tr></tr><tr></tr>
<tr bgcolor=#$tcolor1>
<td colspan=2 align=center>
<input type=submit value=" Sign Guestbook " style="font-family: Arial; font-size: 10pt">
<input type=reset value=" Reset " style="font-family: Arial; font-size: 10pt">
<input type=hidden name="action" value="add">
</td>
</tr></form>
<tr></tr><tr></tr>
<tr bgcolor=#$tcolor1>
<td colspan=2>
<font color=#$alink><b>*</b> <font size=1 face=$fface color=$fcolor>Required field</font>
<font color=#$alink><b>!</b> <font size=1 face=$fface color=$fcolor>Multiple line support, HTML tag filtering</font>
<font color=#$alink><b>#</b> <font size=1 face=$fface color=$fcolor>Valid format checking</font>
</td>
</tr>
~;
} else {
#=========================
# Check and Fix Comment Content
#-------------------------
# To check for any < and > and change them
# to special HTML tag to prevent harm to
# the guestbook. And change newline to <BR>
# which is to support for multiple lines.
#=========================
$comment =~ s/</</g;
$comment =~ s/>/>/g;
$comment =~ s/\n/<br>/g;
#=========================
# Confirm Signned and Preview
#-------------------------
# If passed all checking, add the entry into
# database and display message and preview.
#=========================
open(datas,">>$data");
flock(datas, 2);
print datas "$fullname||$email||$uin||
close(datas);
print qq~
<tr bgcolor=#$tcolor1>
<td colspan=2>
<font size=$fsize face=$fface color=$fcolor>
The following is what you submitted.<br> You can follow the above link to view the guestbook entries.
</td>
</tr>
<tr></tr><tr></tr>
<tr bgcolor=#$tcolor1>
<td colspan=2>
<font size=$fsize face=$fface color=$fcolor>
<font color=#$alink><b>$fullname
~;
print " <a href=\"$homepage\" target=\"_blank\"><img src=http://denniz.dyns.net
print " <a href=\"$uin\"><img src=http://denniz.dyns.net
print "<br>$location\n" if($location);
print qq~
<br>$comment
<br>Date: $date
</td>
</tr>
~;
}
#=========================
# Print Page Footer & Demo ADV
#-------------------------
# This is the coding for the page footer.
# And there is a place for you to place your own ADV,
# change the ADV coding to anything you want.
#=========================
print "</table>";
print qq~
<p><table width=$twidth bgcolor=#$tcolor2 align=$talign cellpadding=$tpadding cellspacing=$tspacing border=$tborder bordercolor=#$tbcolor>
<tr bgcolor=#$tcolor1 align=center>
<td align=center>
<font face=$fface color=$fcolor size=$fsize><b>Learn more about Perl</b></font>
<br>
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
</td>
</tr>
</table>
~;
print "</body></html>";
#=========================
# End of File
#=========================
E-Guest_show.cgi:
-----------------
#!F:/Savant/perl5/bin/perl
$data = 'http://denniz.dyns.net:80
$title = 'Puszels Guestbook'; # page title
$bgcolor = '3C507D'; # background color
$display = '10'; # default # of entries to display per page
$fsize = '2'; # font size
$fface = 'Arial'; # font face
$fcolor = '000000'; # font color
$alink = '003388'; # link color
$avisited = '003388'; # visited link color
$ahover = '2255AA'; # hover link color
$twidth = '550'; # table width
$talign = 'center'; # table align (left/right/center)
$tborder = '1'; # table border size
$tbcolor = '000000'; # table border color
$tpadding = '5'; # table padding size
$tspacing = '5'; # table spacing size
$tcolor1 = 'dddddd'; # table color 1
$tcolor2 = '999999'; # table color 2
#=========================
# NO EDITING AFTER THIS LINE
#=========================
#=========================
# Solve and Set Query String
#-------------------------
# Check if query string. If yes, split
# the string and set them to different
# variables.
#=========================
if ($ENV{'QUERY_STRING'}) {
($s1,$s2,$s3,$s4) = split(/\&/,$ENV{'QUERY_STR
($type1,$value1) = split(/\=/,$s1);
($type2,$value2) = split(/\=/,$s2);
($type3,$value3) = split(/\=/,$s3);
($type4,$value4) = split(/\=/,$s4);
$start = $value1;
$sort = $value2;
$display = $value3;
$search = $value4;
} else {
$start = 0;
$sort = lifo;
}
$stop = $start + $display;
#=========================
# Open Data File and Sort
#-------------------------
# Open the data file and according to the
# query string, sort the data in different
# ways
#=========================
open(temp,"$data");
flock(temp, 2);
@indata = <temp>;
if ($sort eq lifo) { @datass = reverse(@indata); }
elsif ($sort eq lilo) { @datass = @indata; }
elsif ($sort eq name) { @datass = sort(@indata); }
close(temp);
#=========================
# Count Total
#-------------------------
# Open the data file and count how many
# entries are in the database.
#=========================
open(file,"$data");
while(<file>) {
$TheLine = $_;
chomp($TheLine);
$LineCount = $LineCount + 1;
}
close(file);
#=========================
# Print Page Header
#-------------------------
# This is the coding for the heading of
# the page.
#=========================
print "Content-Type: text/html\n\n";
print qq~
<!-- E-Guest guestbook system 1.1 -->
<!-- powered by leungeric.com -->
<html><head><title>$title<
<style>
A:link {text-decoration: none; color: #$alink}
A:visited {text-decoration: none; color: #$avisited}
A:hover {text-decoration: underline; color: #$ahover}
</style>
<body bgcolor=#$bgcolor>
<table width=$twidth bgcolor=#$tcolor2 align=$talign cellpadding=$tpadding cellspacing=$tspacing border=$tborder bordercolor=#$tbcolor>
<tr bgcolor=#$tcolor1 align=center>
<td>
<font face=$fface color=$fcolor><b>$title
<p align=right><font size=1>powered by <a href=http://leungeric.com target=_blank>leungeric.co
</td>
</tr>
</table>
<p>
<table width=$twidth bgcolor=#$tcolor2 align=$talign cellpadding=$tpadding cellspacing=$tspacing border=$tborder bordercolor=#$tbcolor>
<tr bgcolor=#$tcolor1>
<td colspan=2 align=center>
<font size=$fsize face=$fface color=$fcolor>
<b><a href=E-Guest_sign.cgi>Sign
</td>
</tr>
~;
#=========================
# Search and Submit
#-------------------------
# This is the coding for the searching
# feature. Included an text input field
# and a submit button.
#=========================
print qq~
<tr bgcolor=#$tcolor1>
<td width=50% align=center>
<font size=$fsize face=$fface color=$fcolor>
<form name=form1>
<input type=hidden name=display value=0>
<input type=hidden name=sort value=$sort>
<input type=hidden name=entry value=$display>
<input type=text name=search size=10 style="font-family: Arial; font-size: 10pt" value=$search>
<input type=submit value=Search style="font-family: Arial; font-size: 10pt" onSubmit="self.location=do
<input type=button value="Reset" style="font-family: Arial; font-size: 10pt" onClick="self.location='E-
</td></form>
~;
#=========================
# Total Entries Message
#-------------------------
# This is the coding for the message
# which displays the total number of
# messages
#=========================
print qq~
<td width=50% align=center>
<font size=$fsize face=$fface color=$fcolor>
There are $LineCount messages
</td>
</tr><form>
<tr bgcolor=#$tcolor1>
<td width=50% align=center>
<font size=$fsize face=$fface color=$fcolor>
Display
<select style=\"font-family: Arial; font-size: 10pt\" onChange=\"if(this.options
~;
#=========================
# Entry Number Menu
#-------------------------
# The drop down menu which control how many
# entries to be displayed per page.
# and If the option is using already, set
# it as selected.
#=========================
if ($display eq 5) {
print "<option selected value=E-Guest_show.cgi?dis
} else {
print "<option value=E-Guest_show.cgi?dis
}
if ($display eq 10) {
print "<option selected value=E-Guest_show.cgi?dis
} else {
print "<option value=E-Guest_show.cgi?dis
}
if ($display eq 15) {
print "<option selected value=E-Guest_show.cgi?dis
} else {
print "<option value=E-Guest_show.cgi?dis
}
if ($display eq 20) {
print "<option selected value=E-Guest_show.cgi?dis
} else {
print "<option value=E-Guest_show.cgi?dis
}
print qq~
</select>
per page
</td></form><form>
<td width=50% align=center>
<font size=$fsize face=$fface color=$fcolor>
Sort by
<select style=\"font-family: Arial; font-size: 10pt\" onChange=\"if(this.options
~;
#=========================
# Sort List Menu
#-------------------------
# The drop down menu which control how
# to sort the entries. Like LIFO, LILO
# or in alphabetical.
# and If the option is using already, set
# it as selected.
#=========================
if ($sort eq lifo) {
print "<option selected value=E-Guest_show.cgi?dis
} else {
print "<option value=E-Guest_show.cgi?dis
}
if ($sort eq lilo) {
print "<option selected value=E-Guest_show.cgi?dis
} else {
print "<option value=E-Guest_show.cgi?dis
}
if ($sort eq name) {
print "<option selected value=E-Guest_show.cgi?dis
} else {
print "<option value=E-Guest_show.cgi?dis
}
print "</select></td></form></tr
#=========================
# Format and Display Entries
#-------------------------
# With a FOR loop and condition, display
# the corresponding entries.
# Becos not all fields are required,
# Set if field value is here, display the
# corresponding code.
#=========================
$match = $start;
$matchcount = 0;
for($i = $start; $match < $stop && $i < $LineCount; $i++) {
$newdata = $datass[$i];
($name,$email,$UIN,$url,$p
if ($name =~ /$search/i) {
$match++;
$lastmatch = $i;
$matchcount++;
print "<tr bgcolor=#$tcolor1><td colspan=2>" if ($name);
print "<font size=$fsize face=$fface color=$fcolor>" if ($name);
print "<font color=#$alink><b>$name</b>
print " <a href=\"$url\" target=\"_blank\"><img src=http://denniz.dyns.net
print " <a href=http://wwp.icq.com/sc
print "<br>$place\n" if($place);
print "<br>$comment\n" if($comment);
print "<br>Date: $date\n" if ($name);
print "</td></tr>" if ($name);
}
}
#=========================
# No Matching Entry
#-------------------------
# If no matching entry is found in
# database, then display a message about
# it.
#=========================
if ($matchcount == 0) {
print qq~
<tr bgcolor=#$tcolor1><td colspan=2 align=center>
<font size=$fsize face=$fface color=$fcolor>
No matching entry found!
</td></tr>
~;
}
#=========================
# Check for Next Matches
#-------------------------
# With a FOR loop, check if there are
# more matching entries.
# If yes, we'll display a NEXT link for
# going to the next page.
#=========================
$morematch = 0;
$findstart = $lastmatch + 1;
for($i = $findstart; $i < $LineCount; $i++) {
$newdata = $datass[$i];
($name,$email,$UIN,$url,$p
if ($name =~ /$search/i) {
$morematch++;
}
}
#=========================
# Check for Prev Matches
#-------------------------
# With a FOR loop, check back the index
# number for the last page.
# Becos, number of entry to display and
# the search condition can be changed
# anytime, so we have to check the index
# number for the PREV link.
#=========================
$prevmatch = 0;
$prevstart = $start - 1;
for($i = $prevstart; $i >= 0 && $prevmatch < $display; $i--) {
$newdata = $datass[$i];
($name,$email,$UIN,$url,$p
if ($name =~ /$search/i) {
$prevmatch++;
$previndex = $i;
}
}
#=========================
# Display Next and Prev Links
#-------------------------
# After the checking, then we can decide
# if it'll display a NEXT and PREV links
# for going to the next or prev page.
#=========================
print "<tr></tr><tr></tr><tr>";
print "<td bgcolor=#$tcolor1 align=center><b><font size=$fsize face=$fface color=$fcolor><a href=\"E-Guest_show.cgi?di
print "<td bgcolor=#$tcolor1 align=center><b><font size=$fsize face=$fface color=$fcolor><a href=\"E-Guest_show.cgi?di
#=========================
# Print Page Footer & Demo ADV
#-------------------------
# This is the coding for the page footer.
# And there is a place for you to place your own ADV,
# change the ADV coding to anything you want.
#=========================
print "</tr></table>";
print qq~
<p><table width=$twidth bgcolor=#$tcolor2 align=$talign cellpadding=$tpadding cellspacing=$tspacing border=$tborder bordercolor=#$tbcolor>
<tr bgcolor=#$tcolor1 align=center>
<td align=center>
<font face=$fface color=$fcolor size=$fsize><b>Learn more about Perl</b></font>
<br>
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
<A HREF="http://www.amazon.co
<IMG SRC="http://leungeric.com/
</td>
</tr>
</table>
~;
print "</body></html>";
#=========================
# End of File
#=========================
and
E-Guest_db.txt:
-----------------
a plain empty text file.
The problem is that nothing is written in
the E-Guest_db.txt file, even if the scripts
seem to work...until you click on the link
"View Guestbook".
The url is:
http://denniz.dyns.net:808
Main Topics
Browse All Topics





by: maneshrPosted on 2001-12-30 at 09:12:06ID: 6701425
peterx,
"..All three files, 2 perl and the db text-file are in the cgi-bin folder.."
Can you post the Perl script here? Can you post theHTML file that you are using here?
Can you post the URL where one can see this HTML form & Perl script in action?
The info that you have provided is not clear. Therefore, pl. explain in plain english what exactly you are trying to do, what is happening & what you expect to happen.
This will help you get a more accurate answer, faster.