Perl cgi redirect not working

Charles Howse chowse at charter.net
Sun Oct 5 11:50:26 PDT 2003


> > #!/usr/bin/perl
> >
> > 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])/pack("C", hex($1))/eg;
> >             ^
> >     $value =~ s/~!/ ~!/g;
> >             ^   ^   ^
> >     $FORM{$name} = $value;
> > }
> >
> > print "Content-type: text/html\n\n";
> >
> > open (MAIL,"| /usr/sbin/sendmail -oi -t");
> > print MAIL "From: $FORM{'name'} <$FORM{'email'}>\n";
> > print MAIL "To: charles\n";
> > print MAIL "Subject: Contact form output\n\n";
> > print MAIL "$FORM{'name'}, from $ENV{'REMOTE_HOST'}
> > ($ENV{'REMOTE_ADDR'}), has sent you the following comment:\n\n";
> > print MAIL "$FORM{'comment'}\n";
> > close (MAIL);
> >
> > print "Location: http://howse.no-ip.org/thanks.shtml\n\n";
> >
> 
> 1) This is a little extreme for a simple redirect.  A simple 
> 3 liner will
>    do the trick:
> 
>   #!/usr/bin/perl
> 
>   print "Location: http://howse.no-ip.org/thanks.shtml\n\n";
>   exit;

Actually, this was a CGI script to respond to an email form on my
website.
When I posted asking the same question on a newsgroup, I was flamed so
severely for using "buggy, crappy" code that got busy, did some
research, and have moved 'up' to FormMail.pl, which is working perfectly
now.

The problem with the book code is that 'Content-type' line.
Removing it fixes that code.

> 
> 2) They are suppose to be tildes (~).

Thank you for a respectful answer.  :-)




More information about the freebsd-questions mailing list