develooper Front page | perl.beginners | Postings from January 2002

Re: What's wrong with this?

From:
Jeff 'japhy' Pinyan
Date:
January 24, 2002 13:39
Subject:
Re: What's wrong with this?
Message ID:
Pine.GSO.4.21.0201241636320.9276-100000@crusoe.crusoe.net
On Jan 24, Eduardo Cancino said:

>The next script runs looks pefectly in IE but in Netscape it shows the
>source of the html...

That is because IE does things that a browser should not do.

># recibe la forma.
>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>@pairs = split(/&/, $buffer);

Ugh.  You should not try to deal with incoming form information yourself
-- use the standard CGI.pm module.  Please.

># inicia variables.
>$to = "info\@domain.mx";
>$from = "info\@domain.mx";
>$subject = "Comentarios Sitio Web";
>
># manda el mail.
>open (MAIL,"|mail $to");
>print MAIL <<"END_top";
>
>"To: $to
>Reply-To: $to:
>Subject: $subject"
>
>END_top

That's not working, I can promise you that.

  print MAIL << "END_top";
  To: $to
  Reply-To: $to
  Subject: $subject

  END_top

Notice I didn't quote the surrounding text.

>foreach $pair (@pairs)
>{
>   ($name, $value) = split(/=/, $pair);
>    $value =~ tr/+/ /;
>    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>    $form{$name} = $value;
>
>   if ($form{$name} ne "" && $form{$name} ne "no" && $name ne 'enviar') {
>      print MAIL $name . " = ". $form{$name} . "\n";
>  }
>}

This is bad too.  Use CGI.pm.  Please.

>
>close MAIL;
>
># imprime html.
>print <<WEB_page;
>
>Content-type: text/html
><!doctype html public "-//w3c//dtd html 3.2 final//en">

Here's the primary problem.  You cannot place a newline before the HTTP
headers, and you MUST place an extra newline AFTER the HTTP headers.

  print << "WEB_page";
  Content-type: text/html

  <!doctype ...>
  ...
  WEB_page

Notice the difference?

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About