how to show a triggerd welcome message only on the first login?

vallab444 - September 11, 2009 - 15:09

I show a user welcome message on my site, triggered on user login. However, I want to restrict this only to the first or the initial few logins of a new user. Is there a way to achieve this non-programmatically? How do I check if it is the first or 'N' th login?

thanks!

User Stats

Bacteria Man - September 11, 2009 - 15:52

I've never used it myself, but you might want to check out User Stats, which includes a login counter. You'd still need a helper module to produce the count-sensitive messaging though. The idea is something like this VERY crude example:

function hook_user($op, &$edit, &$account, $category = NULL) {
  // $account assumes you have a fully loaded user object containing user stat properties
  if ($op == 'login') {
    switch ($account->login_count) {
      case 0:
      case 1:
         drupal_set_message(t("Hey, welcome new user!"));
         break;
      case 2:
         drupal_set_message(t("Hey, you look familiar..."));
         break;
      default:
        drupal_set_message(t("Hey, good to see you again old-timer."));
    }
  }
}

-------------------------------------------------------

"I remember that sound. That's a bad sound."
-- Gwen DeMarco

 
 

Drupal is a registered trademark of Dries Buytaert.