I have a little script(for the web) that I am playing with. All this script needs to do is take a group of specific params and make sure that there is info in there (not necessary if it is correct) and then take any other ones that may appear put them all into an email and send it. The mechanics of the script work fine but when I run it with other people my copy will sometimes get their data and vise-versa. It will sometimes duplicate the information inside the email. So far I have only noticed it when I hit refresh repeatedly, but I am affraid that this could become a "privacy" issue. I don't know if the CGI object is causing this, my script being stupid, or Apache. I have run it on different Apache configurations with the same problem.
#!/usr/bin/perl
# Setting up my include files
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Net::SMTP;
undef $/;
# Creating objects
my $q = "";
$q = new CGI;
my $email_body = "";
my @params = $q->param;
my %param = {};
my %product_names = ( 'product_a' => 'Product A',
'product_b' => 'Product B');
foreach (@params) {
$param{$_} = 1;
}
$email_body.="calling HANDLE_PERSONAL_INFORMATION\n";
HANDLE_PERSONAL_INFORMATION();
$email_body.="calling HANDLE_PRODUCTS\n";
HANDLE_PRODUCTS();
PRINT_HEADER();
SEND_EMAIL($email_body);
#print $email_body;
exit;
sub HANDLE_PRODUCTS {
#this is where I will do all the product handling
my @last_params = keys %param;
$email_body.="Listing products selected:\n";
foreach (@last_params) {
$email_body .= $product_names{$_} . "($_): " . $q->param($_) . "\n
+" if($q->param($_) != 0);
}
}
sub HANDLE_PERSONAL_INFORMATION {
my $order_num = $_[0];
my @personal_information = ('name', 'street', 'city', 'state', 'zi
+p', 'phone', 'email');
my @errors = HANDLE_INFORMATION(@personal_information);
if(($errors[0] != 0) || ($#errors > 1)){
# I have created an error please help
PRINT_HEADER();
HANDLE_ERRORS(@errors);
PRINT_FOOTER();
exit;
}
}
sub HANDLE_INFORMATION {
my @columns = @_;
$email_body.="Inside HANDLE_INFORMATION with columns: @columns\n";
my @errors = ();
foreach (@columns){
my $temp = $q->param("$_");
if($temp ne ''){
delete($param{$_});
$email_body .= uc $_;
$email_body .= ": $temp\n";
} else {
#debuging
push @errors, $_;
}
}
if($#errors == 0){
return 0;
} else {
return @errors;
}
}
sub HANDLE_ERRORS {
#######################################
# This handles all the errors that #
# the user causes #
#######################################
foreach (@_){
my $temp = ucfirst($_);
print "<font color=red>$temp is required</font><br>\n";
}
print "Please hit the back button and fill out all the fields\n";
}
sub PRINT_HEADER {
print $q->header;
print <<EODUMP;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PAGE TITLE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1
+">
</head>
<body bgcolor="#FFFFFF" text="#000000">
HEADER GOES HERE
EODUMP
}
sub PRINT_FOOTER {
print <<EODUMP;
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
EODUMP
}
sub SEND_EMAIL {
my $smtp = Net::SMTP->new("my.email.server") or HANDLE_ERROR("Can
+not submit. System Down.");
$smtp->mail ('email@domain');
$smtp->to ('email@domain');
$smtp->data();
$smtp->datasend("To: email\@domain\n");
$smtp->datasend("From: email\@domain\n");
$smtp->datasend("Subject: Order\n");
$smtp->datasend("\n");
$smtp->datasend($email_body);
$smtp->dataend();
$smtp->quit;
print "Your order has been submitted.<br>\n";
print "You should be contacted shortly<br>\n";
my @array = split(/\n/, $email_body);
foreach(@array){
print "$_<br>";
}
}
I really think it is an Apache issue. Has anyone else had this? Thanks
--
BigJoeLearn patience, you must.
Young PerlMonk, craves Not these things.
Use the source Luke.