Recording User logins/logoffs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ajcg2903
Forum Newbie
Posts: 3
Joined: Tue Sep 14, 2010 2:37 am

Recording User logins/logoffs

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Recording User logins/logoffs

Post 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?
jazzercising011
Forum Newbie
Posts: 9
Joined: Tue Sep 14, 2010 4:47 am

Re: Recording User logins/logoffs

Post 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
ajcg2903
Forum Newbie
Posts: 3
Joined: Tue Sep 14, 2010 2:37 am

Re: Recording User logins/logoffs

Post 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...;
stuartr
Forum Newbie
Posts: 13
Joined: Sun Sep 12, 2010 11:11 am

Re: Recording User logins/logoffs

Post 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.
ajcg2903
Forum Newbie
Posts: 3
Joined: Tue Sep 14, 2010 2:37 am

Re: Recording User logins/logoffs

Post by ajcg2903 »

thank you. That's helpful. I'll give it a go!
Post Reply