Page 1 of 1
Recording a user's last login date and then retrieving it
Posted: Thu Jun 15, 2006 12:02 pm
by Luke
I am building a file manager and I would like any files that have been uploaded since a user's last login to show up in a different color or something, but I can't FOR THE LIFE OF ME figure out how that can be accomplished... I've been cracking away at it all morning... anybody? Thanks in advance!
Posted: Thu Jun 15, 2006 12:14 pm
by TheMoose
Whenever a user logs in, store that login time in a database. Then every time a file is uploaded, record that upload time in a database. If the user's login time is less than the file upload time, that means the file was uploaded after their latest login, so change the color. If the login time is greater than the upload time, that file was uploaded before their last login, so do the normal color. What you could also do is have it store their LOGOUT time instead, that way it will truely be the files since they last visited the page.
Pseudo:
Code: Select all
user_login_time = store_login_time();
if(user_login_time < file_upload_time)
file_is_new;
else
file_is_old;
Posted: Thu Jun 15, 2006 2:05 pm
by Luke
TheMoose wrote:What you could also do is have it store their LOGOUT time instead, that way it will truely be the files since they last visited the page.
This is what I am trying to do. I don't need to save the time files were uploaded into a database, because the server records that information anyway. I can retrieve that with filemtime(). The reason I am having problems is because what if the user doesn't actually log out? What if they just close the window? How would I then insert that information in the database? Maybe i could use cookies or something? I've never actually worked directly with cookies. (just with session functions). any advice?
Posted: Thu Jun 15, 2006 3:32 pm
by TheMoose
On each page load, you can store the time the page loaded in the database (their last activity). I believe the default timeout for sessions is 20 minutes, so you can take the last activity time, and if the current time is 20 minutes after that time, then you can assume that the person left the page since there is no more activity.
Posted: Thu Jun 15, 2006 3:32 pm
by tecktalkcm0391
You can have the your user database have a field for logged in, ever page would update the field to 1, and then make another field for update login time. And then have a cron-job that goes and check if current time is greater than 15 min set 1 to 0 and then store the current time as their last login time. Then just make it so if checks the time the user last logins and when the files were uploaded and if its after the last login time, have PHP print a color code or whatever you want.
Posted: Thu Jun 15, 2006 3:40 pm
by RobertGonzalez
One of the techniques I use is to track user activity. I keep track of their IP, their login status, their admin level, their user status, their last login time, their last page and last page load time. Just those pieces of information alone can be used for any number of things that you might want to show (ie, Who's logged in, what has happened since your last loging, where the users are geographically [though IP geo locating is unreliable], etc).
Posted: Thu Jun 15, 2006 3:48 pm
by bdlang
Everah wrote:One of the techniques I use is to track user activity. I keep track of their IP, their login status, their admin level, their user status, their last login time, their last page and last page load time. Just those pieces of information alone can be used for any number of things that you might want to show (ie, Who's logged in, what has happened since your last loging, where the users are geographically [though IP geo locating is unreliable], etc).
I'm curious, do you use a seperate table for this or within the 'users' table? I've always used a seperate table myself.
Posted: Thu Jun 15, 2006 3:53 pm
by John Cartwright
bdlang wrote:Everah wrote:One of the techniques I use is to track user activity. I keep track of their IP, their login status, their admin level, their user status, their last login time, their last page and last page load time. Just those pieces of information alone can be used for any number of things that you might want to show (ie, Who's logged in, what has happened since your last loging, where the users are geographically [though IP geo locating is unreliable], etc).
I'm curious, do you use a seperate table for this or within the 'users' table? I've always used a seperate table myself.
I tend to keep logging information in it's own table..
Posted: Thu Jun 15, 2006 3:55 pm
by RobertGonzalez
I usually keep everything related to the user in the user table. Though you can probably do this anyway you want. If you want to keep a running log then I would suggest you place this information into a separate table. If you are only interested in what is happening now or what has happened since the last time, keeping that data in the user table should work without a problem.
Posted: Thu Jun 15, 2006 4:04 pm
by printf
bdlang wrote:I'm curious, do you use a seperate table for this or within the 'users' table? I've always used a seperate table myself.
If your not really using the data, other than to show the user their activity, I would create another table this way you only access the data in a JOIN, I would also just use (2) columns, the user_id as the ref key, and a text column, then serialize the activity data. But like I said I would only do that if it was for display purposes only. If it was for more, then I would keep certain values in their own column so I could select, update and delete certain data that I want to manage!
pif!
Posted: Thu Jun 15, 2006 4:16 pm
by bdlang
Everah,
Jcart,
printf>
Thanks for your responses; I actually tend to do both. I always have an `activity_date` update-always TIMESTAMP column in the `user` table (along with the generic, update-once-only `register_date` column). Then depending on the application I have a `user_activity` table that stores the UserID and the other current info as previously mentioned. That way you can prune outdated `user_activity` records as needed and still store the last activity date for every user.
It's like anything, everybody has a unique way of doing things, I'm always curious of other's methods so I can learn a better way. I like
printf's logic of storing a serialized array of user data, for example.
