Detect when user accesses the site
Drupal saves the timestamp of a user's last access, but by the time your can react to a user visiting the site, that value has already been overwritten with the current timestamp (that happens in sess_write()). I don't have a cut-and-paste solution for you, but there are some ideas how to store the previous timestamp for later use in this forum topic.