Last login script
-
Hi there,
I’ve got this script to update a table in my database with the logout time of a user, then when they log in next time, this data is shown in the form of “Last login: date time”.
However this isnt working, and was hoping for some help.
Posted in functions.php
function userloginvarset($login){ global $user_ID; global $userlogininfo; $userlogininfo = get_user_by('login',$login); } add_action('wp_login','userloginvarset'); function last_login($login) { update_usermeta($userlogininfo->ID, 'last_login', current_time('mysql')); } add_action('wp_logout','last_login'); function get_last_login($user_id) { $last_login = get_user_meta($user_id, 'last_login', true); $date_format = get_option('date_format') . ' ' . get_option('time_format'); $the_last_login = mysql2date($date_format, $last_login, false); echo $the_last_login; }
and
Posted in page.phpglobal $userdata; get_currentuserinfo(); echo('Welcome '.$userdata->display_name.'!</br>'); _e('Last login:'); get_last_login($userdata->ID);
the displaying of the data works fine, its just the updating of the table. Thanks in advance
- The topic ‘Last login script’ is closed to new replies.