Hello Everyone,

I have installed Drupal, got my themes working, and added some content, but now I want to display a different default starting page for my Anonymous Users than for users that are already logged in.

How do I do the following default pages based on whether or not a user is authenticated?:

Anonymous Users:

Welcome to the Alpha site - please login with your credentials to enter the site.

The Alpha site is available by invite only, please email us at: email@domain.com to get access to this site.

Authenticated Users:

Welcome to the Alpha site - introduction page.

Thanks,
Natalie

Comments

zbricoleur’s picture

First, put this in the template.php file in your theme:

function _phptemplate_variables($hook, $variables) {
  global $user;
   switch($hook) {
     case 'page' :
        $variables['logged_in'] = $user->uid;
        break;
   }
  return $vars;
}

That will add $logged_in to the variables available to your page.tpl.php file. Empty the database cache to activate that.

Then add a snippet to the top of page.tpl.php (and page-front.tpl.php if you have one, and any other page.tpl files you have):

<?php
if (!$logged_in && arg(0) !== 'user') { // arg(0) !== 'user' tells you they're not on the login page!
  header("Location: WelcomeURL");
}
elseif ($logged_in) {
  header("Location: IntroURL");
}
?>

Substitute the appropriate absolute URLs for WelcomeURL and IntroURL.

Natalie-1-1’s picture

Thanks for the tips... This seemed to work well.

I used your code snippets above to prevent my banner images from appearing for non-authenticated users.

I ended up going with the "Advanced Front Page" module which allows you to have different administrable content on your front page for authenticated and non-authenticated users.

Thanks,
Natalie