Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

guestbook perl script help - comments written incorrectly to server

Status
Not open for further replies.

jamo81

Programmer
Jul 11, 2007
3
0
0
GB
Hi there. I am new to these forums.

I have written for a guestbook on my website, which seems to work fine apart from when the comment is posted, it updates onto the server side host as:

host86-143-178-97.range86-143.btcentralplus.com - [Thu Jul 5 18:17:16 2007 ]

The part scripting for the date seems to work, but the comments themselves do not. Something is written but it is not what people type in client side.

I have chmodded all the files correctly (755).

Any help would be much appreciated, thank you.
 
I doubt anyone can help you without seeing your perl code or just the relevant part of your perl code.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Sorry - thought it was quite long - here's the relevant parts of the script...

#!/usr/bin/perl
require "ctime.pl";

# Set Variables

$guestbookurl = "$guestbookreal = "../comments/guestbook.html";
$guestlog = "../comments/guestlog.html";
$cgiurl = "$date_command = "/usr/bin/date";

# Set Your Options:
$uselog = 1; # 1 = Yes; 0 = No
$linkmail = 1; # 1 = Yes; 0 = No
$separator = 1; # 1 = <hr>; 0 = <p>
$entry_order = 1; # 1 = Newest entries added first;
# 0 = Newest Entries added last.
$allow_html = 1; # 1 = Yes; 0 = No
$line_breaks = 0; # 1 = Yes; 0 = No


# Done
##############################################################################

# Get the Date for Entry
$date = &ctime(time);
$shortdate = &ctime(time);

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;

if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}

$FORM{$guestbook} = $value;
}

# Print the Blank Response Subroutines
&no_comments unless $FORM{'comments'};
&no_name unless $FORM{'realname'};

# Begin the Editing of the Guestbook File
open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;

# Open Link File to Output
open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!\n";

for ($i=0;$i<=$SIZE;$i++) {
$_=$LINES[$i];
if (/<!--begin-->/) {

if ($entry_order eq '1') {
print GUEST "<!--begin-->\n";
}

if ($line_breaks == 1) {
$FORM{'comments'} =~ s/\cM\n/<br>\n/g;
}

print GUEST "<b>$FORM{'comments'}</b><br>\n";

if ($FORM{'url'}) {
print GUEST "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
}
else {
print GUEST "$FORM{'realname'}";
}

if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print GUEST " \&lt;<a href=\"mailto:$FORM{'username'}\">";
print GUEST "$FORM{'username'}</a>\&gt;";
}
else {
print GUEST " &lt;$FORM{'username'}&gt;";
}
}

print GUEST "<br>\n";


if ( $FORM{'country'} ){
print GUEST " $FORM{'country'}";
}

if ($separator eq '1') {
print GUEST " - $date<hr>\n\n";
}
else {
print GUEST " - $date<p>\n\n";
}

if ($entry_order eq '0') {
print GUEST "<!--begin-->\n";
}

}
else {
print GUEST $_;
}
}

close (GUEST);

# Log The Entry

if ($uselog eq '1') {
&log('entry');
}


#######################
# Subroutines

sub no_comments {
print "Content-type: text/html\n\n";
print "<html><head><title>No Comments</title></head>\n";
print "<body><h1>Your Comments appear to be blank</h1>\n";
print "The comment section in the guestbook fillout form appears\n";
print "to be blank and therefore the Guestbook Addition was not\n";
print "added. Please enter your comments below.<p>\n";
print "<form method=POST action=\"$cgiurl\">\n";
print "Your Name:<input type=text name=\"realname\" size=30 ";
print "value=\"$FORM{'realname'}\"><br>\n";
print "E-Mail: <input type=text name=\"username\"";
print "value=\"$FORM{'username'}\" size=40><br>\n";
print "name=\"country\" value=\"$FORM{'country'}\" size=15><p>\n";
print "Comments:<br>\n";
print "<textarea name=\"comments\" COLS=60 ROWS=4></textarea><p>\n";
print "<input type=submit> * <input type=reset></form><hr>\n";
print "Return to the <a href=\"$guestbookurl\">Guestbook</a>.";
print "\n</body></html>\n";

# Log The Error
if ($uselog eq '1') {
&log('no_comments');
}

exit;
}

sub no_name {
print "Content-type: text/html\n\n";
print "<html><head><title>No Name</title></head>\n";
print "<body><h1>Your Name appears to be blank</h1>\n";
print "The Name Section in the guestbook fillout form appears to\n";
print "be blank and therefore your entry to the guestbook was not\n";
print "added. Please add your name in the blank below.<p>\n";
print "<form method=POST action=\"$cgiurl\">\n";
print "Your Name:<input type=text name=\"realname\" size=30><br>\n";
print "email: <input type=text name=\"username\"";
print " value=\"$FORM{'username'}\" size=40><br>\n";
print "value=\"$FORM{'state'}\" size=2> Country: <input type=text ";
print "value=USA name=\"country\" value=\"$FORM{'country'}\" ";
print "size=15><p>\n";
print "Comments have been retained.<p>\n";
print "<input type=hidden name=\"comments\" ";
print "value=\"$FORM{'comments'}\">\n";
print "<input type=submit> * <input type=reset><hr>\n";
print "Return to the <a href=\"$guestbookurl\">Guestbook</a>.";
print "\n</body></html>\n";

# Log The Error
if ($uselog eq '1') {
&log('no_name');
}

exit;
}

# Log the Entry or Error
sub log {
$log_type = $_[0];
open (LOG, ">>$guestlog");
if ($log_type eq 'entry') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate]<br>\n";
}
elsif ($log_type eq 'no_name') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No Name<br>\n";
}
elsif ($log_type eq 'no_comments') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No ";
print LOG "Comments<br>\n";
}
}


# Print Response
print "Thank you for filling in the guestbook. Your entry has\n";
print "been added to the guestbook.<hr>\n";
print "Here is what you submitted:<p>\n";
print "<b>$FORM{'comments'}</b><br>\n";

if ($FORM{'url'}) {
print "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
}
else {
print "$FORM{'realname'}";
}

if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print " &lt;<a href=\"mailto:$FORM{'username'}\">";
print "$FORM{'username'}</a>&gt;";
}
else {
print " &lt;$FORM{'username'}&gt;";
}
}

print "<br>\n";


if ( $FORM{'country'} ){
print " $FORM{'country'}";
}

print " - $date<p>\n";

# Print End of HTML
print "<hr>\n";
print "<a href=\"$guestbookurl\">Back to the Guestbook</a>\n"; print "- You may need to reload it when you get there to see your\n";
print "entry.\n";
print "</body></html>\n";

exit;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top