0

I have been trying to get a quick easy way to redirect the user, no matter where they go to the site straight to the user login page. But before I do, I want to redirect them to another page saying some message like "Sorry, you need to be authenticated to view blah blah... you are being redirected to the login page".

I currently have:

function mytheme_preprocess_page(&$vars, $hook) {
  global $user;
  if ($user->uid == 0 && arg(0) != 'user'){
    drupal_goto('user/login');
  }
}
1

Before the goto call you can add drupal_set_message( $message, $status);

Its the more straightforward solution, although the message will be displayed inside the login page and there wont be any delay.

Or just change the goto path to a custom... 'user/sorry' page with your message, and something like:

 <div onLoad="setTimeout('myRedirect()', 6000)"></div>

and a JavaScript function

function myRedirect(){ window.location = "user/login"; }

Add the standard "if you are not redirected, click here" link in case JavaScript is disabled.

  • This is a great idea. I need a quick/simple solution. Thanks a ton @Astrayus – tdm Feb 14 '14 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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