title: PHP Last log in script
body: <p>I wanted to know a good and efficient way to be able to tell how long ago my users last logged in.</p>
  
  <p>On the users profile I want it for say how long ago their last log in was.</p>
  
  <p>Eg:</p>
  
  <p>User 1
  Last login: 2 hours ago</p>
  
  <p>User 2
  Last login: 3 minutes ago</p>
  
  <p>User 3
  Last login: 2 months ago</p>
  
  <hr>
  
  <p>I will keep their last login information in a MySQL database but want to know how to do the script.</p>
  
  <p>I just realized that Stackoverflow uses this feature, so that can help you understand what I want.</p>
  
  <hr>
  
  <pre><code>mysql_query("UPDATE users SET lastactivity = ".time()." WHERE id = ".$userID);
  </code></pre>
  
  <p>This is how I will update the DB.</p>