We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials
More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsDrupal

How to display last login time

Linux Cloud Server
Linux KVM Hosting
KVM VPS
Windows Cloud Server
USA VPS
OpenVZ VPS
cPanel KVM
Germany Cloud Servers
Ubuntu VPS
Brazil VPS

By default, Drupal does not display the time of the last login. To enable this, you need to add some additional code to the Drupal core engine. This is one example of how to edit the core engine to achieve this function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!--?php 
function module_user($op, &#038;$edit, &#038;$account, $category = NULL) {
switch($op) {
case 'load':
$account-&gt;custom_last_login = sizeof($account--->custom_login_history) &lt; 2
? NULL
: array_pop($account-&gt;custom_login_history);
break;
 
case 'login':
$login_history = is_array($account-&gt;custom_login_history)
? $account-&gt;custom_login_history
: array();
 
if (sizeof($login_history) == 2) {
array_pop($login_history);
}
 
array_unshift($login_history, $account-&gt;login);
 
user_save($account, array('custom_login_history' =&gt; $login_history));
break;
}
}
?&gt;

What this code does is that it simply displays timestamps of current and previous login times. The mentioned code block will have to be inserted in Drupal modules code in order to be working properly. Now it is possible to insert this function in the place you want to see last login time. You can insert it by using the following code:

1
$user-&gt;;custom_last_login

In most cases it can be inserted from a currently activated template. Once it is inserted, you should be able to see the time of the last Drupal log in.

Windows Cloud Server
Brazil VPS
KVM VPS
Germany Cloud Servers
OpenVZ VPS
USA VPS
Ubuntu VPS
Linux Cloud Server
Linux KVM Hosting
cPanel KVM
Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Other (195)

Popular Keywords