I am using a free script called AlienForm [cgi.tj] that processes form input and sends off e-mail. I've got the script working fine on a couple of different servers (Apache *nix), but can't seem to get the time off of any of them. In the script documentation they show an example using DATE_GMT [cgi.tj] to get the time off the server, but I've yet to get it to work for me. I sent an e-mail to my host asking why this didn't work, and they responded that DATE_GMT is not a standard CGI environment variable, but there should be other ways of accomplishing the same thing...
My question is, using this script, how could I get the current time off the server without access to DATE_GMT or DATE_LOCAL, neither of which seem to be available to me?
But if you want to manipulate what Perl gives you, go to About.com's Perl section [perl.about.com].
#determine local time
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$isdst="";$wday=""; # second use of vars to stop errors
if (length ($hour) eq 1) {$hour= "0".$hour;}
if (length ($min) eq 1) {$min= "0".$min;}
if (length ($sec) eq 1){$sec= "0".$sec;}
if (length ($mon) eq 1) {$mon= "0".$mon;}
if (length ($mday) eq 1) {$mday= "0".$mday;}
$mon++;
$year =~ s/.*(..)$/$1/;
if ($year < 90) { $year = "20" . $year; }
$nowdate = "$year-$mon-$mday $hour:$min:$sec";
print MAIL @_;
On the next line, insert the code that volatilegx just showed you.
And add one more line:
print MAIL $nowdate;
When done, the subroutine will look like:
sub SendMail {
if ($smtp_server) { SendMailSMTP(@_) }
else {
# check that mailer exists and is executable:
unless(-X $mail_cmd) {Error('Mailer Command Error', "The mailer '$mail_cmd' does not exist, or is not executable."); return}
open(MAIL,"¦$mail_cmd $mail_flags") ¦¦ Error('Mailer Open Error',"An error occurred when trying to open the mailer ($mail_cmd): $!.");
print MAIL @_;
Here's a little formula for determining time:
#determine local time
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$isdst="";$wday=""; # second use of vars to stop errors
if (length ($hour) eq 1) {$hour= "0".$hour;}
if (length ($min) eq 1) {$min= "0".$min;}
if (length ($sec) eq 1){$sec= "0".$sec;}
if (length ($mon) eq 1) {$mon= "0".$mon;}
if (length ($mday) eq 1) {$mday= "0".$mday;}
$mon++;
$year =~ s/.*(..)$/$1/;
if ($year < 90) { $year = "20" . $year; }
$nowdate = "$year-$mon-$mday $hour:$min:$sec";
print MAIL $nowdate;
close(MAIL) or Error('Mail Send Error',"An error occurred when sending the email: $?. Please check the email's headers.");
}
}
Could I ask for a little more guidance? The hosting company I'm currently using has its servers somewhere around Puerto Rico...the webs I'm taking care of are for Japan and China...would it be possible to add a few hours to this hack? For example, Japan is GMT +9, would it be possible to adjust this script to reflect Japan time?
I hate to admit it, but I believe I was the inspiration for the 99.99% of High School Seniors Can't Read Perl... [webmasterworld.com] article.