Page 1 of 1

Recording User logins/logoffs

Posted: Tue Sep 14, 2010 2:43 am
by ajcg2903
I have a small club website with login using an sql server hosted on a remote host. I want to be able to record whish users login when. Are there any solutions in php code that will write data to eg a text file on the server?

Re: Recording User logins/logoffs

Posted: Tue Sep 14, 2010 3:01 am
by requinix
Not only is it too trivial to bother writing a "tutorial" about, what you do can vary so much that there isn't really a cut-and-paste answer.

You have something that logs people in, right? Do you know how to open and write to a file?
Do you know about concurrency? File locking?
Any reason it should be a file and not a database? Do you care about a detailed list or do you just want to know the last-logged-in time?

Re: Recording User logins/logoffs

Posted: Tue Sep 14, 2010 5:24 am
by jazzercising011
Yeah what that guy said, it varies too much to write a tutorial on. What I would do is on the login success page have it append their username and the date to a text file.

this should definitely help you along though:

http://www.tizag.com/phpT/fileappend.php

Re: Recording User logins/logoffs

Posted: Thu Sep 16, 2010 4:54 am
by ajcg2903
Thank you. Hope I find it trivial!! I can probably open and write to a txt log file. I will try, thanks.. Can't use another dbase - we are a charitable club - all our cash goes to charitable causes and not for running the club - and are limited by the host provided to 1 database under our contract...;

Re: Recording User logins/logoffs

Posted: Thu Sep 16, 2010 6:03 am
by stuartr
It doesn't need to be a new database, you could simply add a table to your existing database to record logon/logoff events.

There are pros and cons to holidng in a table vs a text file - personally I would probably go with the database table approach as you could then construct queries and reports against the data much easier that with a text file. Text files can also be picky about being accessed and written to by two different processes simultaneously unless you initiate some form of file locking.

Re: Recording User logins/logoffs

Posted: Mon Sep 20, 2010 5:01 am
by ajcg2903
thank you. That's helpful. I'll give it a go!