General developer forum

lastlogin / lastaccess disparity

 
Picture of David Dixon
lastlogin / lastaccess disparity
 

Hi folks

I wonder if anybody else has come across this. I have a 1.8.7 moodle install using ldap for authentication. I've noticed that there is a disparity between the lastlogin time recorded in the user table and the stats held in user_lastaccess. For example, quite a number accounts have zero in lastlogin yet data in the user_lastaccess table. First of all I thought this could be explained by people “logging is as”, but the issue is too widespread for this. Any ideas?

Foolishly I made some use of last login in some custom code I did, and it has come back to bite me.  I do understand, by the way, that last access and last login are not the same things.

Much appreciated

Dave

 
Average of ratings: -
Catalyst logo
Re: lastlogin / lastaccess disparity
Core developersPlugin developers
This response may be a bit late, but I was just looking into the same thing and it may be helpful for other people. The crux of it is that 'lastlogin' actually records the last-but-one time that a user has logged in.

There are two related fields in the mdl_user table that get updated when a user logs in: 'currentlogin' and 'lastlogin'. Each time a user logs in:
- 'currentlogin' gets updated with the present time
- 'lastlogin' gets updated with the previous value of currentlogin.

So currentlogin has the user's most recent login time. And lastlogin has their second-most-recent login. Moodle seems to use the 'lastlogin' field for things like saying to the user when they log in, 'You last logged in on July 3'.

currentlogin and lastlogin both start out at 0 when a user account is newly created. The first time a user logs in, currentlogin will get populated with a date but lastlogin will remain 0. So, users with a 0 for lastlogin but a non-zero lastaccess and user_lastaccess records are actually users who have logged in exactly once.
 
Average of ratings: Useful (8)
Picture of Nate Baxley
Re: lastlogin / lastaccess disparity
Plugin developers
Thanks Aaron! Late or not it helped answer the question for me!

Nate
 
Average of ratings: -
Picture of Michael Cohn
Re: lastlogin / lastaccess disparity
 

You want to talk about late... I just found this conversation and it saved my sanity. Thanks!

 
Average of ratings: -
Picture of James Cruickshank
Re: lastlogin / lastaccess disparity
 

Me too smile

 
Average of ratings: -
picture of Scott Braithwaite
Re: lastlogin / lastaccess disparity
 

just found it also and this brings some clarity to why I get some of the results I get this may just have saved my sanity ;)

 
Average of ratings: -