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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write Date/Time to txt file-How? 1

Status
Not open for further replies.

TulsaJeff

Programmer
Jan 29, 2001
870
US
I simply want to write the current date and time to a txt file each time a user logs in. It can overwrite the old data each time the user logs in so there would only be one date and time. Each user would have their own text file.

I am wanting to read the "last login" into a variable in Flash.

I have the login username/password authentication working within Flash and would rather not change any of that. I just want to use a simple if statement within Flash to determine who logged in so the date and time can be written to that persons .txt file.

Any ideas or help? Ya' Gotta Love It!
sleepyangelsBW.jpg
 
Hi - you can write the current date and time to a file like this.

$datetime = scalar(localtime(time));
open(F,'>datetime.dat') || die $!;
print F $datetime;
close(F);
Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
I have the following in a file which writes the date to a .txt file.

#!/usr/local/bin/perl
$datetime = scalar(localtime(time));

print "Content-type: text/html\n\n";
print "1datetime=$datetime\n";

open(F,'>1datetime.txt');
print F "datetime=$datetime";
close(F);


the 1datetime.txt seems to be working and shows the datetime=Fri Mar 1 19:57:18 2002 in WS_FTP view ,however, it will not pull it up online... says server error. I have it chmodded correctly I think. Any ideas as to why it would be doing this or is my code totally wrong? The 1datetime.pl shows fine in both WS_FTP view and online. This is like my first attempt at perl... I know a little VB and just enough javascript and actionscript in Flash to be dangerous so I could be way off base.

I was given some code above and I merely tweaked it a little and tried to run it...

I have 7 users, my flash loads the users .pl file when they log in and it writes the date to their .txt file. The man in charge has a user page set up which pulls all these 7 variables from their personal .txt files and is able to see when they logged on last.

There is most likely a better way of doing this with an array or such but this is the best I have come up with considering my limited knowledge of perl.

I took the die part off as well... what is that anyway and do I need to leave it in the code?

I am open for ideas and someone please look at my code and see if it could be causing the server error. Ya' Gotta Love It!
sleepyangelsBW.jpg
 
I can't help you with your CGI problem, but I can explain the die command.

open(F,$file) || die "Can't open $file $!\n";

In the above command the die command will only be executed if the open() function fails.

die prints the message you give it as a parameter and stops the script with a non-zero error code.

If you're using perl to generate HTML you can get error messages to your brower by using the Carp module with the fatals_to_browser option. Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Getting something to run as a CGI app is fairly straight forward.
1 - first make sure the syntax is good with perl -c your_code.pl on your machine. That does not run the code, nor does it check all dependencies, but, if you forgot a semi-colon or quote, it will complain.

2 - if you have all required modules on your machine, you can run the code from a prompt to see if you get compliant HTML back.

3 - move the code onto the server
- Make sure the execute bits are set. It has been a while
since I used WS_FTP, but I think I remember that you
could do this as part of the upload.
- If you wrote your code on a Win PC and you are putting
it on a *nix machine, you'll need to change the line
endings in your code. Again, I think WS_FTP will do
this on the fly.

4 - Make sure that any system dependencies on the server are supported.
- if you are load modules, make sure they exist on the
server
- Assuming Apache here....others are generally similar
if you are trying to write files to the server, make
sure the http daemon has permission to write to the
locations to which you are trying to write. Remember,
all CGIs run as the http daemon. Any decent sys admin-
istrator will setup the daemon with very restricted
abilities for security reasons. So, if your code is
trying to write a file into a directory, 'you' may
be able to via WS_FTP(because you are logging in as
'you') and the http daemon will fail. The easiest and
least sophsticated fix is to open the permissions on
any used directory to 777. Ideally, you would do a
little better than that by coordinating the user:group
and permissions so that the directory would be
specifically set up for the http daemon.



'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top