Last updated May 28, 2009. Created on May 23, 2007.
Edited by bekasu, LeeHunter, add1sun, chx. Log in to edit this page.

  1. Make 'denied' the 403 page.
  2. While you could pull the login form as the login block does and 4.7 and onwards it automatically submits -- but the registration tab would not appear. Solving this is very difficult, see http://drupal.org/node/88707 for further details (D6 solved this by rehauling the menu system from ground up). Add this to any hook_menu implementation in the $may_cache part. This is extremely important, this part must be cached.
    <?php
        $items
    [] = array(
         
    'access' => !$user->uid,
         
    'path' => 'denied',
         
    'callback' => 'mymodule_denied',
         
    'type' => MENU_CALLBACK,
        );
    ?>
  3. To your module, add:
    <?php
    function mymodule_denied() {
      global
    $user;
      if (
    $user->uid) {
        return
    t('Access denied');
      }
     
    drupal_goto($_GET['q'], 'login=1');
    }
    ?>
  4. To settings.php add
    <?php
    function custom_url_rewrite($op, $result, $path) {
      if (
    $op == 'source' && !empty($_GET['login'])) {
        return
    'user/login';
      }
      return
    $result;
    }
    ?>

Another Option

Another way of doing this is with panels. http://www.proofgroup.com/blog/2008/sep/drupal_combining_login_registrat...

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.