In this case we are going to build a simple login and register block that links to drupal login and register page.

The aim in this tutorial is to build the simple block using drupal create block feature only.

Now to start the building, we need to point our self to drupal block management area at admin/build/block.

In the admin/build/block area, there is a link to build a new block in the primary tabs, click the "Add block" link in the primary tabs.

After you click the "Add block" link you will be pointed to admin/build/block/add, in this page you will have a form to build a new block.

We need to build 2 blocks, One is the link to login or register page and the other is for the message that will be shown to the user who login and a logout link for that user.

Now, building the first block "login or register" : Under block specific fieldset : 1. Input "login or register" in the block description textfield 2. Input "" in the block title 3. Input :

 

return l(t('Login'), 'user') . '  |  ' .  l(t('Register'), 'user/register');

 

in the block body area Under Role Specific Visibility Setting : 1. click on "anonymous user" check box Now lets save our first block, Next create the second block "greetings or logout" .

Before your proceed you need to enable input php filter for this to work.

To enable it you need to enable the PHP filter module that comes with drupal. Under block specific fieldset :

1. Input "greetings or logout" in the block description textfield

2. Input "" in the block title 3. Input :


  global $user;
  if ($user->uid > 0) {
     $username = $user->name;
  }

  return  t('Greetings') . ', ' . $username .  '   |   ' . l('Logout', 'logout');

in the block body area Under Role Specific Visibility Setting :

1. click on "authenticated user" check box

2. optional click on any other roles that you have in the site if necessary.

Now you need to save the second block.

The last step is to put those two blocks in the same block region that you wish for both of it to show.

 

Enjoy your simple login + register + greeting + logout block.