I need to redirect an anonymous user when they hit the url 'node/add/project' to 'user/login' - otherwise, just leave them enter that url.

Not sure if I'm going about this the correct way (probably not as it doesn't appear to work!) - Can someone shed some light, or advice!

function local_menu() {
    $items['node/add/project'] = array(
        'page callback' => 'local_project_anonymous',
        'access callback' => TRUE,
        'type' => MENU_CALLBACK,

    return $items;

function local_project_anonymous(){
    global $user;
    if($user->uid == 0){


  • Why don't you create a permission, and use it for the menu callback?
    – Simkamil
    May 31, 2012 at 14:59

2 Answers 2

function MODULE_init(){
  global $user;
  if ($user->uid == 0  && $_GET['q'] == 'node/add/project' ) {

Maybe you can use the LoginToboggan module.

The LoginToboggan module offers several modifications of the Drupal login system in an external module by offering the following features and usability improvements:

  • Allow users to login using either their username OR their e-mail address.
  • Allow users to login immediately.
  • Provide a login form on Access Denied pages for non-logged-in (anonymous) users.
  • The module provides two login block options: One uses JavaScript to display the form within the block immediately upon clicking "log in". The other brings the user to a separate page, but returns the user to their original page upon login.
  • Customize the registration form with two e-mail fields to ensure accuracy.
  • Optionally redirect the user to a specific page when using the 'immediate login' feature.
  • Optionally redirect the user to a specific page upon validation of their e-mail address.
  • Optionally display a user message indicating a successful login.
  • Optionally combine both the login and registration form on one page.
  • Optionally have unvalidated users purged from the system at a pre-defined interval.
  • Integrates with the Rules module to do various tasks when a user validates via email validation process (see http://drupal.org/node/880904 for an example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.