freelanceprogrammers.org Forum Index » Perl
My infamous script. Urgent need a help
Joined: 14 Jun 2004
Posts: 4
My infamous script. Urgent need a help
Hello,
The following script gets "Premature end of script headers error". If
I type print header("text/html") at the bottom (after the else and
befoire get_uncessful_page function) the script works, but the page
is not properly redirected. The html header will be appended to the
url and it obviously doesn`t work.
If I type header("text/html") *before* the if logic (the if after
close(MAIL)), the script will also work but instead of redirecting to
any of Location:url it will print "Location:myurl" in the page,
because the print "Location:url" must be typed before any output in
order to work.
I cannot get around of this problem. I`m unable to get a working
script which redirects.
Additionnally I get a warning:
Use of uninitialized values or string
(for the line print MAIL "To: $sitemails{$id_site}"; and print
MAIL "IP Addr: $remote_ip
";)
This doesn`t make sense at all. Both variables %sitemails and
$remote_ip are ABSOLUTELY INITIALIZED.
Please, help me and tell me what it`s wrong with this script.
Thanks
Alph
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
$CGI::DISABLE_UPLOADS = 1; # Disable uploads
# Hash defining the sitecodes associated with their respective email.
Uncomment it if
# Need to use it.
# The single quote turns off the @ special meaning of variable
interpolation
my %sitemails= (`s0403`, `infopublic@...`,
`s0403p`, `infopublic@...`,
`s0403e`, `infopublic@...`,
);
my $remote_ip = $ENV{`REMOTE_ADDR`};
my $mailprog = "/usr/sbin/sendmail";
my $name = param(`fullname`) || ``;
my $email = param(`email`) || ``;
my $subject = param(`subject`) || ``;
my $section = param(`section`) || ``;
my $lng = param(`lng`) || ``;
my $site = param(`site`) || ``;
my $id_site = param(`id_site`) || ``;
my $message = param(`message`) || ``;
if ( $name =~ /[^A-Za-z.,; ]/ || length($name) > 50
|| $email =~ /\n|[;,<>*/`()&$#\%]/ || length($email) > 50
|| $subject =~ /\n/ || length($subject) > 100
|| $section =~ /\n[;,<>*/|&`()$#\%]/ || length($section) > 30
|| $lng =~ /\n[;,.<>*/|&`()$#\%]/ || length($lng) > 2
|| $site =~ /\n[;,<>*|&`()$#\%]/ || length($site) > 100
|| $id_site =~ /\n[;,.<>*/|&`()$#\%]/ || length($id_site) > 6
|| length($message) > 2000)
{
show_unsuccessful_page();
}
open (MAIL, "|$mailprog -t");
print MAIL "To: $sitemails{$id_site}";
print MAIL "From: $email
";
print MAIL "Subject: [$id_site] $subject
";
print MAIL "Section: $section
";
print MAIL "IP Addr: $remote_ip
";
print MAIL "Message:
=======================
$message
";
close (MAIL);
#SECTION B
if($id_site eq "s0403"){
print "Location: http://www.mysite.com/confirm.html";
}elsif ($id_site eq "s0403e"){
print "Location: http://www.mysite2.com/confirm.html";
}elsif ($id_site eq "s0477"){
print "Location: http://www.mysite3.com/confirm.html";
}elsif ($id_site eq "s0403p" || $id_site eq "s0477p"
|| $id_site eq "s0702p" || $id_site eq "s0726p"){
print header("text/html");
print start_html();
print "<script language=`javascript`>
";
print "<!--
";
print "history.go(-2)
";
print "//-->
";
print "</script>";
print end_html();
}else{
print header("text/html");
print start_html("Error Page");
print "<h3>Message sent, but ID site invalid</h3>";
print end_html();
}
sub show_unsuccessful_page
{
print header("text/html");
# When this page is shown, no message is actually sent. But
the bad guy thinks
# that it was, and will not try harder
start_html("Message Sent");
print "Message Sent
";
end_html();
exit;
}
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







