
Lark
Novice
Jan 2, 2004, 12:59 PM
Post #4 of 26
(4116 views)
|
|
Re: [Lark] server change causing error messages
[In reply to]
|
Can't Post
|
|
ok, here it is... #!/usr/bin/perl print "Content-type:text/html\n\n"; #=========================== # Initialize the variables #=========================== # Relative path of Guestbook.html $guestbook_file = '../guestbook/guestbook.html'; # Initialize list of months @month = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); #=========================== # Read the data from the form #=========================== if($ENV{'REQUEST_METHOD'} eq "POST"){ $data_length = $ENV{'CONTENT_LENGTH'}; $bytes_read = read(STDIN, $my_data, $data_length); } # Let's load it into something we can use @name_value_array = split(/&/, $my_data); # Here's where we do the actual work. We're going to cycle # through @name_value_array to decode the name=value pairs foreach $name_value_pair (@name_value_array) { # Split the name=value pair in your HTML form data ($name, $value) = split(/=/, $name_value_pair); # Now, replace '+' with ' ' $name =~ tr/+/ /; $value =~ tr/+/ /; # Next, we'll translate any hex values back into characters $name =~ s/%(..)/pack("C",hex($1))/eg; $value =~ s/%(..)/pack("C",hex($1))/eg; # Finally, we'll load the variables into an associative array # so we can use it when we need it. if($form_data{$name}) { $form_data{$name} .= "\t$value"; } else { $form_data{$name} = $value; } } #=========================== # Get the date and time # information #=========================== ($Seconds, $Minutes, $Hours, $DayInMonth, $Month, $ShortYear, $DayOfWeek, $DayOfYear, $IsDST) = localtime(time); # Make the year four digits instead of just two $Year = $ShortYear + 1900; $EntryDate = "$month[$Month] $DayInMonth, $Year"; #=========================== # Open the file, using the # variable set at the beginning # of the script. #=========================== open(GUESTBOOK, "<$guestbook_file") || die "Can't open GUESTBOOK: $guestbook_file\n"; # Read the entire file into a list so we can use it later @guestbook =<GUESTBOOK>; # ALWAYS close the file when you're done! close(GUESTBOOK); #=========================== # Now open it again, but this # time we'll write to it #=========================== open(GUESTBOOK, ">$guestbook_file") || die "Can't open GUESTBOOK: $guestbook_file\n"; #=========================== # Here's where we write it out #=========================== foreach $line (@guestbook){ # Check to see if we're at the beginning of the guest book if($line =~ /<!--My Latest Guest:-->/i) { #=========================== # We are, so add our latest guest # Start by adding the guestbook # header to the file, so we can # find it next time #=========================== print GUESTBOOK "<!--My Latest Guest:-->\n"; #=========================== # The guestbook is an HTML # file, so we'll have to add # the tags too #=========================== print GUESTBOOK "<DL>\n"; #=========================== if($form_data{'email'}) { print GUESTBOOK "<DD><I><B><A HREF=\"mailto:$form_data{'email'}\"> $form_data{'name'}</A></B></I>\n"; } else { print GUESTBOOK "<DD><B>From : </B><I> $form_data{'name'}</I>\n"; } print GUESTBOOK "<DD><B>Period: </B><I>$form_data{'period'}</I>\n"; #=========================== #=========================== print GUESTBOOK "<DD><B>Homepage:</B><I><A HREF=\"$form_data{'web'}\">$form_data{'web'}</A></I>\n"; #=========================== #=========================== # add the comments print GUESTBOOK "<P>\n"; print GUESTBOOK "$form_data{'comments'}\n"; print GUESTBOOK "</P>\n"; #=========================== #=========================== # add the date print GUESTBOOK "<p><I><font size=2>\n"; print GUESTBOOK "signed on $EntryDate\n"; print GUESTBOOK "</font></I>\n"; #=========================== #=========================== # finish up print GUESTBOOK "</DL>\n"; print GUESTBOOK "<HR color=blue size=3>\n"; #=========================== }# end: if($line =~ /<!--My Latest Guest:-->/i) else { #=========================== # just print the existing # lines back to the updated file #=========================== print GUESTBOOK "$line"; }# end: else[if($line =~ /<!--My Latest Guest:-->/i)] }# end: foreach $line (@guestbook) { close(GUESTBOOK); #open (MAIL, "|sendmail -t"); #print MAIL "To: $form_data{'name'}<$form_data{'email'}>\n"; #print MAIL "From: Mr. Larkins <larkinst\@conway.afsc.k12.ar.us>\n"; #print MAIL "Thank you $form_data{'name'} for signing my guestbook. You should be able to view it immediately.\n"; #print MAIL "You submitted the following information to www.MrLarkins.com.\n"; #print MAIL " \n"; #print MAIL "Name: $form_data{'name'}\n"; #print MAIL "Email Address: $form_data{'email'}\n"; #print MAIL "Web Address: $form_data{'web'}\n"; #print MAIL "Class Period: $form_data{'period'}\n"; #print MAIL "Comments:\n"; #print MAIL "$form_data{'comments'}\n"; #print MAIL " \n"; #print MAIL "Thanks.\n"; #print MAIL "Mr. Larkins\n"; #close (MAIL); #open (MAIL, "|sendmail -t"); #print MAIL "To: Mr. Larkins <tlarkins\@conwaycorp.net>\n"; #print MAIL "From: $form_data{'name'}<$form_data{'email'}>\n"; #print MAIL "Subject: I signed your guestbook\n\n"; #print MAIL "$form_data{'name'} submitted the following entry to your guestbook.\n"; #print MAIL " \n"; #print MAIL "Name: $form_data{'name'}\n"; #print MAIL "Email Address: $form_data{'email'}\n"; #print MAIL "Web Address: $form_data{'web'}\n"; #print MAIL "Class Period: $form_data{'period'}\n"; #print MAIL "Comments:\n"; #print MAIL "$form_data{'comments'}\n"; #close (MAIL); #=========================== # Let them know their entry # is added #=========================== print <<"EOF" <HTML><TITLE>Entry Submitted</TITLE><HEAD> <META HTTP-EQUIV="refresh" content="4;URL=/home/virtual/site160/fst/var/www/guestbook/guestbook.html"></HEAD><BODY> <H1>Your GuestBook Entry has been Submitted\!</H1> Your guestbook entry has been successfully added to the guestbook and in <font size=24>3</font> seconds you will be taken back to view it. </BODY> EOF #===========================
|