View Full Version : script for logging to a file from html form
sausage
01-09-2003, 01:55 PM
I there im new to perl coding and im looking for a script that can let me log the results of an html form to a file on my server. I have a few form mail scripts i have looked at but i really need it to log to a file and not email the results to myself. If anyone can help me i would be most grateful.
Thanks
Jim
optimism_
01-09-2003, 08:56 PM
Hi.
Im a bit new to perl too, but not to comp programming in general :) I imagine the flow would be
To read in tha data
To open a file
To write/append the data
To Close the file
To write a response.
I think i would be right in saying that all of these are covered in the perl/cgi programming tutorials on webmonkey (http://www.hotwired.com/webmonkey)
Have a look see!
----------------------------------------
my comp just keeled over and died; no really, a victim of 0xc0000034
----------------------------------------
[ msn: optimism_@hotmail.com ]
Hi sausage
You can use one of the mail-form scripts and cut it up a bit.
Remove the send mail lines and insert the following at the end of the script:
open (LOGFILE, ">> NAME_OF_FILE_YOU_WANT_TO_LOG_TO.txt") ;
flock(LOGFILE, 2) ; ##### LOCK - comment for locking on a non-Unix server.
seek(LOGFILE, 0, 2) ; ##### LOCK - comment for locking on a non-Unix server.
print LOGFILE "$companyname\t$sendername\t$senderemail\t$sendertele\t$comments\t$datetime\t$url\n" ;
flock(LOGFILE, 8) ; #### LOCK - comment for locking on a non-Unix server.
close (LOGFILE) ;
After print LOGFILE you will see $companyname and $senderemail etc. Replace these with whatever the names of your form fields are - so long as you also make sure they correspond with the rest of the perl script. After the first $, you must use t$. I think this puts in the tabs ((not sure but I know you need it!).
Hope this helps - I am not that good with perl, but I know this works for sure. I've added it to many perl scripts!
Don't foget to CHMOD the text file to 722 (all, write only, write only).
sausage
01-11-2003, 04:51 PM
Thanks very much , I will go and try that and let you know how i get on.:) :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.