• Home
  • Contact
  • Forum
  • Get help or hire me
  • Get paid!

The How to site

Office tips, CSS, PHP, MySQL scripting and web publishing

Feed on
Posts
Comments

Forum

Apr 1st, 2008 by Jesper

Current User: Guest Login Register
Please consider registering

Search 
Search Forums:


 




Home Forums Wordpress Wordpress latest user login hack

Wordpress latest user login hack
Read original blog post

Reply to Post
Page: 1
UserPost

11:27 pm
April 1, 2008


Jesper

Admin

posts 5

 Quote and Reply
 Report Post
1

I needed a way to log the date and time the last time a user logged in I looked around for a plugin to do this for me, but found none, so I decided to try and write a function myself.

This one I struggled with and in the end it came out like something of a abomination of a function, but at least it gets the job done. It uses the WP_AUTHENTICATE hook to call the function where a simple login check is done, and if successful, the timestamp is writted to the wp_users table.

You can either insert a new field called user_lastlogin (or what you prefer) in wp_users like I did, or you can make a new table to store the login log.

The code follows below. Happy logging!


function update_last_login($user_login=”, $user_pass=”, $cookie=false)
{
if ($_POST) {
global $wpdb;
$success=0;
// check login $_POST variables against database
$query = “SELECT ID FROM wp_users WHERE user_login=’$user_login[0]’ AND user_pass=’”.md5($user_login[1]).”‘”;
$uid = $wpdb->get_var($query);
if ($uid!=”) {$success=1;}
$login_time = date(”Y-m-d H:i:s”, time()+28800);
// if login is successful, update user last login
if ($success==1) {
$query = “UPDATE wp_users SET user_lastlogin=’$login_time’ WHERE user_login=’$user_login[0]’”;
$wpdb->query($query);
}
}
}
// Hook action — this is needed to call the function when someone logs in
add_action(’wp_authenticate’,'bm_update_last_login’,10,2);


Read original blog post

Page: 1 Reply to Post


Reply to Topic: Wordpress latest user login hack

NOTE: New Posts are subject to administrator approval before being displayed

Guest Name (Required):

Guest EMail (Required):

Guest URL (required)

Math Required!
What is the sum of: 5 + 10        (Required)

Topic Reply:


 
Topic RSS 

About the The How to site forum

Currently Online:

1 Guest

Maximum Online: 8

Forums:

Groups: 2

Forums: 5

Topics: 5

Posts: 5

Members:

There are 1 members

Jesper has made 5 posts

Top Posters:

Administrator: Jesper


© Simple:Press Forum - Version 3.0.2 (Build 318) Patch 1 

Popularity: 3% [?]

Share This

Comments are closed.

  • Categories

    • Advertising
    • Blogging etc
    • CSS
    • DevLog
    • Excel
    • Hardware
    • Misc
    • News
    • Screencasts
    • Scripting
    • web development
    • Word
    • Wordpress
  • Recent Posts

    • Creating a simple histogram in Excel 2007
    • Quality control chart for Excel 2007
    • Integrating a forum with your Wordpress installation
    • Wordpress latest user login hack
    • Running a cronjob with Godaddy shared hosting
    • Web development success and failure
    • Firefox add-on: GraphSense for AdSense
    • Really simple roundes corners with CSS
    • Web advertising eCPM comparison
    • New Excel 2007 add-in facilitate web data mining
  • Partner

  • Recent Comments

    • Praveen on Box plot for Excel 2007
    • Jesper on Box plot for Excel 2007
    • Hemant Bhatye on Dynamic text fields in Word header
    • Art on Box plot for Excel 2007
    • Art on Box plot for Excel 2007
  • Meta

    • Register
    • Login
    • Entries RSS
    • Comments RSS
    • WordPress.com

The How to site © 2008 All Rights Reserved.

MistyLook made free by Web Hosting Bluebook


Close
  • Social Web
  • E-mail
  • del.icio.us
  • Digg
  • Furl
  • Netscape
  • Yahoo! My Web
  • StumbleUpon
  • Google Bookmarks
  • Technorati
  • BlinkList
  • Newsvine
  • ma.gnolia
  • reddit
  • Windows Live
  • Tailrank
E-mail It