chomp.cgi

 


#!/usr/bin/perl

if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
        @pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{
    read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/, $buffer);

    if ($ENV{'QUERY_STRING'})
    {
        @getpairs =split(/&/, $ENV{'QUERY_STRING'});
        push(@pairs,@getpairs);
    }
}
else
{
    print "Content-type: text/html\n\n";
    print "<P>Use Post or Get";
}

print "Content-type: text/html\n\n";


$comments = $formdata{'comments'};

print "<P>Before cleaning the data, the comments are <PRE>--$comments--</PRE>";

while ($comments =~ /\s$/) 
{
    chop ($comments);
}

print "<P>After cleaning the data, the comments are <PRE>--$comments--</PRE>";
	

open (LOG, ">>../logs/logfile.txt") || &ErrorMessage;
print LOG "$comments\n";
close (LOG);

print "<P>You commented thusly: <BLOCKQUOTE><P><I>$comments</I></BLOCKQUOTE>\n";
print "<HR>Would you like to see all the messages? <A HREF=\"http://www.setgetweb.com/cgi-bin/readfromlog.cgi\">Yes</A>";

sub ErrorMessage {
	print "Content-type: text/html\n\n";
	print "The server can't open the file. It either doesn't exist or the permissions are wrong. \n";
	exit;
}