I created a simple menu link and need it to be visible for both authorized and anonymous users. But when a unauthorized/anonymous user click it should check authorization and if not it should redirect to login page. How can i do this. Thanks


Create a custom module In your_custom.module

function custom_init(){
global $user;
$current_path = request_path();
if (!in_array(array('your roles','your roles'),$user->roles) && $current_path=="node/add/yourcontent type" ) {
  // for mutiple row

If you made the link via the drupal admininstration area and Menu or Menu Items ... or you've made the menu item using hook_menu() ... then you just need to define an 'access callback' for the menu item. See hook_menu() documentation for how to do this -- if the user is anonomous then you will return False from this custom callback function.

If you dont have a custom hook_menu() in a function but made the menu item via the Adminstration UI, then implement hook_menu_alter() to change the menu item stored in the database and add the "access argument".

If you're just echoing an html link in some page without having the link come from the database .... good luck.


Yes you can do this just go to admin/config/system/site-information (if using drupal 7) there you will see a Error Pages title at the bottom of the form there you can see an option as Default 403 (access denied) page. You can mention your login page path within that text box user/login. I hope this works for you

  • Well that's a different thing. I've a menu link and it will be visible to both authorized and anon users. When user clicks the menu link, based on the user-type it should either access the page or redirect of login page. – uzair Mar 27 '12 at 11:02

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.