Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a mail form to a log file?

Status
Not open for further replies.

caffeinerusher

Programmer
Mar 7, 2001
31
US
Hello,

I have a simple form that a customer fills out and submits it. A CGI takes the contents of the form and sends it as an email. Do do some recent problems with our server it has been requested that I also write the contents of the form to a log file. I would need each submission of the form (probably 20-30 a day) to be written to the same file. Can anybody help?

--Caffeinerusher
 
A general treatment of the situation,
Once you have the $contents you want to print to your log file.

Code:
# number of seconds since jan 1, 1970 ,( I think, 1-1-1970??)
$date = localtime; 

$logFile = '/path/to/your/log/file.txt';
open(LOGFILE,">>$logFile") or die "Failed to open log file, $!\n";
flock LOGFILE, 2; # lock the file
print LOGFILE &quot;<entry>\n$date -> $contents\n</entry>\n&quot;;
flock LOGFILE, 8; # unlock the file
close LOGFILE;

You could enclose your form data elements in xml-ish tags
to make them easy to parse later or just delimit them with
pipes or some other infrequently used char. if you use
delimiters, be sure you do not print any into the LOGFILE
in the $contents.

'hope this helps...


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top