First question:
to print the current date and time (from the server) you can use the built in function localtime:
$mydate = localtime(time);
this will produce a string in the format:
Sun Jun 24 08:03:23 2001
and you can hack it around as you see fit.
second question:
data from a form comes in two flavours:
GET and POST the way i found is better, is to deal with the both in every script, to cover yourself.
This way i can cut and paste the following code what ever the script i'm writing is going to deal with:
my $in;
if ($ENV{'REQUEST_METHOD'} eq "GET" {
$in = $ENV{'QUERY_STRING'};
} else {
$in = <STDIN>;
}
this lovey for loop makes life that much easier, it takes each name=value pair (and form data comes in this format) and makes it $data{name} = value;
now yu have all your data in the aso array %data and labeled by its form name. Handy no?
writing to a file? this is fun again we have two flavours, deleting any current file content, and writing a fresh file, or appenending an exisiting one (adding ot the end of it)
open(MEFILE, ">myfile.dat"
print MEFILE "$what_I_want_to_write";
close(MEFILE);
that opens a file, deletes whatever it holds, and writes to it,
open(MEFILE, ">>myfile.dat"
print MEFILE "$what_I_want_to_write";
close(MEFILE);
that opens a file, and adds to the end of it, note the extra >
its a good idea to use a || die "Didn't open $!"; on the end when you open a file, so you can easily debug if it doesn't work
I tried the localtime thing before, but I don't really like it because it doesn't show it in the 12hr format. Can you tell me how to do that? Thanks again. :-D
I'm making an admin logging part on my script and it looks like:
open (FILE, ">>/home/puremadnezz/cgi-bin/test/variables/vars_log.cgi" or die("Unable to open vars_log.cgi file for writing."
flock(FILE,LOCK_EX);
print FILE qq!$Gen|username|password|$Date|$IP|$Host\n!;
flock(FILE,LOCK_UN);
close (FILE);
chmod(0777, "/home/puremadnezz/cgi-bin/test/variables/vars_log.cgi"
As far as i can see there, the only problem is your appending the file, not writing to it, so its adding to what was already in the file.
Having worked on a IIS server for the most part of my time, i never used flock or chmod, why are you using them here?
you can write to your own dat files without all that messing around.
also i'd be tempted to put the vars you want to write, in speechmarks like so:
thats about all i can come up with. Check on the CGI board for a goood login script i wrote for someone else (under Help! CGI-BIN NEWBIE" or something i think
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.