Redirect authenticated Drupal users

posted by Ishmael Sanchez on Oct 28, 2010

So I was recently working on a project and there was a requirement to have anonymous users view a simple homepage with a sign up form. This is easy enough, create a page (/node/add/page) and add the sign up form (See below, quick and dirty), and set the default front page to this newly created node on /admin/settings/site-information.

Prints out the Drupal registration form usually found on /user/register
include_once(drupal_get_path('module', 'user') .'/user.module');
print drupal_get_form('user_register')

So this works great, but when an authenticated users visit the homepage they will see the registration form which is somewhat confusing. To make things more user friendly we can redirect them to an overview page. We can do this with a simple custom module. Once you have your module folder and basic .info file set up add the following code to your .module file.

* Redirect authenticated users to overview page instead of homepage
function MYMODULE_init() { global $user; if ($_GET['q'] == 'node/10' and $_SERVER['SCRIPT_NAME'] == '/index.php' and $user->uid) drupal_goto('overview');

Just replace the node id with the id of your actual front page node (see /admin/settings/site-information) and just make sure you have a page with the path overview or some other custom page.


Post new comment

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Ishmael Sanchez