By brashquido on
Hi All,
Just wondering if there was any module/snippet that I can use to display the last login time of a user. I looked at the tracker module, but I can't see that functionality there.
Hi All,
Just wondering if there was any module/snippet that I can use to display the last login time of a user. I looked at the tracker module, but I can't see that functionality there.
Comments
interested in this also
in case anyone knows how to do this, thanks!
if i figure it out, i'll post it here. :-)
Albert
www.ithou.org
Display last login time
Hi,
the last login time is saved in user->login.
E.g. in a module you can add a field with hook_user to the user account view:
in a block or theme you can do a simple echo
It will display the current
It will display the current date and time and not last time the user logged in. I tried it and thats what it does
This is how i did
1. Create a table lh
2. Enter the following line in the user_logout function in user.module file, just after the watchdog function call
3. Used the advanced front page module and created a page for the authenticated users and put the following code. Dont forget to enable php support
Now clicking on Home link will display the users last login date and time
as module, storing in user->data, using hook_user and user_save
I also needed this, but with the help of the holy book 'Pro Drupal Development' (:p) I think I managed to do this the 'better' way. Please note that this is my first piece of Drupal code, so correct or help me anywhere it's needed.
(I don't know if it matters, but I'm using Drupal 5.5)
I developed a tiny module consisting of 4 files:
- LICENSE.txt, telling anyone that this module is distributes under GNU GENERAL PUBLIC LICENSE.
- README.txt, containing:
- user_last_login.info, containing:
- and user_last_login.module, containing:
It works well for me so I believe it's a nice solution for having the last login timestamp available. Again, correct me anywhere I might be wrong or anywhere I could improve something...
Also, can I share this module (through Drupal's contributes modules repository ?) and how do I do that?
Paul
Hmm I believe my code and
Hmm I believe my code and also the code above won't work when a user not actually logs out, but closed his browser and gets re-logged in by his cookie. Then the session where he left without logging out doesn't seem to get recored.
How Can I improve the code?
Does perhaps the load operation run before load?
using the stored value
Of course to use the value 'last_login' just use '$GLOBALS['user']->last_login' and format it with 'format_date'.
In a side block
*Only works in user* and in a block. If u want to use in userprofile-tpl.php, it wont display correctly.
*If user requires verification and he never verifies it, the last access date will display weird years (like 1970) - anyway, only admin can see a non-verified user account
not giving last login time
This code will give the current date and time of when the current page has loadded (last user action), not the previous login time.
think it's working like it should after all
I was after also registering the time when a user re-visits the site after he closed the browser, but turns out there is no hook for that and this seems to not make sense to people, so I stopped trying.
Meanwhile I tried to register the last login time on login insetad of logout, but this neither registered the re-visits.
Anyhow, that code is
Didn't quite work for me...
I found that the posted code for the user hook on login was not quite working. Since the last_login was updated in the db at the time of login, any time the user object was re-loaded from the db the last_login value was actually set to the login time for that session. I was looking for the login time of the previous session. I just ended up stacking the login in times one level deep. I suppose you could give the module a set of config options to keep an arbitrary depth stack of login history. Here is my simplistic (and naive) implementation - essentially popping off the stack:
There's a better way of doing
There's a better way of doing this in drupal 6. I edited the function user_authenticate_finalize(&$edit) in modules/user/user.module.
If you want to display the last time the account was used, symply add a line:
I wanted to display this date so users can check if the account has been used by someone else. $user->access accomplishes this purpose. If you want to display the last login time, I found I had to use an auxiliar variable. Maybe someone can do it cleaner? This is how:
FWIW - slight modification to the login hook
I found that the posted code for the user hook on login was not quite working. Since the last_login was updated in the db at the time of login, any time the user object was re-loaded from the db the last_login value was actually set to the login time for that session. I was looking for the login time of the previous session. I just ended up stacking the login in times one level deep. I suppose you could give the module a set of config options to keep an arbitrary depth stack of login history. Here is my simplistic (and naive) implementation - essentially popping off the stack:
function user_last_login_user($type, &$edit, &$user, $category = NULL) {
if ($type == 'login') {
$currentLogin = $user->login;
$previousLogin = $user->last_login;
$backTwo = $user->last_login_stack;
$newPreviousLogin = array('last_login' => $backTwo);
user_save($user, $newPreviousLogin);
$newBackTwo = array('last_login_stack' => $currentLogin);
user_save($user, $newBackTwo);
}
}
In drupal 6, in table users,
In drupal 6, in table
users, there's a fieldaccess. Probably it can be utilized to get who is the last login..."users" table
In "users" table there is field called 'login' - should that be it?
Keep track of the last two login timestamps
The solution I used: keep track of the last two log-in timestamps (the current and the previous one).
Then in your template you just use
$user->custom_last_login. If it's empty it means we don't have the previous timestamp yet, will be available after the next login.Hi, I'm looking for a way to
Hi, I'm looking for a way to sort a views by the author's last login - so that the most recently logged in authors' nodes would appear first. Any idea how this might be possible?
How to display last login session time
There is a drupal module called login security, which has a checkbox that you can select, that says, display users last login session time, when the user has logged in.