#!/usr/local/bin/perl use CGI qw(:param); print "Content-Type: text/html\n\n"; $logfile = "log2file.log"; open(FILE,">>$logfile") or webdie("Cannot open $logfile for appending: $!"); # localtime() - get today's date, in our local timezone # # 0 1 2 3 4 5 6 7 8 # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # # $year - is number of years since 1900 # $mon - is number of months after January # Other fields are in the format we want. @localtime = localtime(); # this is the same as $localtime[5] = $localtime[5] + 1900; $localtime[5] += 1900; # this is the same as $localtime[4] += 1; $localtime[4] ++; # $datestamp - what is today's date, in YYYY/MM/DD-HH:MM:SS format # # sprintf("format","var1","var2"...) - output a scalar in the prescribed format # %d - output the next variable in the list as a digit # %2d - same as %d, but if less than 10, add a leading space # %.2d - same as %d, but if less than 10, add a leading 0 # %4d - same as %2d, but save room for 4 digits, not just 2 $datestamp = sprintf("%4d/%.2d/%.2d-%.2d:%.2d:%.2d", $localtime[5], $localtime[4], $localtime[3], $localtime[2], $localtime[1], $localtime[0]); # you can also do the above with: $datestamp = sprintf("%4d/%.2d/%.2d-%.2d:%.2d:%.2d", reverse @localtime[0..5] ); # log the time print FILE "$datestamp: "; # log the IP address print FILE "$ENV{'REMOTE_ADDR'} "; # log the paramters sent foreach $parameter (param()) { print FILE "Parameter($parameter) = \"" . param($parameter) . "\", "; } print FILE "\n"; close FILE; # now tell the browser what you did print <

Your parameters have been logged

END sub webdie { print "\n"; print "\n"; print "

Error: $_[0]

\n"; print "\n"; print "\n"; exit 1; }