By robdinardo on
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:
- Login as Administrator
- Add a new block by going to Site Building > Blocks and click Add block (/admin/build/block/add)
- 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:
- Expand "Input format" and choose PHP code
- Click "Save block" to save
- You should now see the list of blocks (if not go to /admin/build/block). Click "configure" for the block you just created.
- 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! - Click "Save block" once again.
- On the block listing page, for the Region choose "content top" then click "Save blocks"
- You're done! You can now test it out by Logging out.
<?php
global $user;
$dest = drupal_get_destination();
if (!$user->uid) {
drupal_goto('user/login',$dest);
}
?>
Enjoy :)
Comments
add this to step 7
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
Not for Drupal 6
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