1

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

3 Answers 3

1

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
  drupal_goto('/user');
}
}
0
0

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.

-2

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

1
  • 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.
    – user3350
    Mar 27, 2012 at 11:02

Your Answer

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