How to redirect to another URL if visitor is anonymous when clicking a menu? I used the following code to redirect anonymous visitor to a login page:

&lt;?php
  global $user;
  if ($user-&gt;uid) {
    print "&lt;a href='http://www.sourcecodester.com/submit'&gt;Submit now...&lt;/a&gt;";
  }
  else {
    print "&lt;a href='http://www.sourcecodester.com/user?destination=submit'&gt;Submit now...&lt;/a&gt;";
  }
?&gt;


But I can do this only in a block. What I want is put a Submit menu in the main menu and if anonymous visitor click the link he/she will be redirect to:

http://www.sourcecodester.com/user?destination=submit

after he/she login, he/she will be redirect again to the submit page as defined in the URL as "destination=submit".

Is this possible in main menu?
you can use Menu per Role module:


  This module allows you to restrict access to menu items1 based on user
  roles. It depends on the Drupal core menu.module—just activate both
  modules and edit a menu item as usual. There will be a new fieldset
  that allows you to restrict access by role. The fieldset also appears
  in the node edit form.