I am creating an intranet site and need to force all anonymous users to the user/login page. I found a post that gave an 'almost' solution, but instead gave me another idea. So, I figured out a clean way to perform the task if anyone is interested. Here's what you do:

  1. Login as Administrator
  2. Add a new block by going to Site Building > Blocks and click Add block (/admin/build/block/add)
  3. For the "Block description" enter something like "Anonymous Redirect" or "Login Redirect". You can leave the "Block title" blank. And for the "Block body" enter the following:
  4. <?php
    
    global $user;
    $dest = drupal_get_destination();
    
    if (!$user->uid) {
        drupal_goto('user/login',$dest);
    }
    
    ?>
    
  5. Expand "Input format" and choose PHP code
  6. Click "Save block" to save
  7. You should now see the list of blocks (if not go to /admin/build/block). Click "configure" for the block you just created.
  8. IMPORTANT - In the "Page specific visibility settings" be sure "Show on every page except the listed pages" is selected and enter the following two lines in the field below:
    user/login
    user

    - if this step is not completed, the anonymous user will be sent into an infinite loop!
  9. Click "Save block" once again.
  10. On the block listing page, for the Region choose "content top" then click "Save blocks"
  11. You're done! You can now test it out by Logging out.

Enjoy :)

Comments

robdinardo’s picture

For Step 7, you should add the line:
user/password

if that line is not added, the user will not be able to request a new password

jacobson’s picture

If you've found this post and are using Drupal 6, know that the method does not work in Drupal 6. I haven't found the problem, yet.

HAJ