hook_permission and control access [how to redirect to the login page if user not logged in] How does one limit "what" can access a page. I have little understanding on how to use hook_permission() to set user permission based on a role to control access to hook_menu() items. However, what if I have a hook_menu() item that is to be used solely by the system itself? For example, say I have a registration page in a custom module: module/register - Anyone can access that page. Then, say I have an another page which is only for admin. So, I register another item in hook_menu(), call it module/register/reg_user_details - I do not want anyone to be able to browse to module/register/reg_user_details 

Instead I want page to be visible only when user is logged in, I have already created a hook_permission 

/**
 * Implements hook_menu()
 * 
 */ 
function video_subtitles_menu() {
  $items = array();
  $items['video_subtitles/upload'] = array( //this creates a URL that will call this form at "video_subtitles_test/upload"
    'title' =&gt; 'Upload Subtitle', //page title
    'description' =&gt; 'Uploading subtitle for videos',
    'page callback' =&gt; 'drupal_get_form', //this is the function that will be called when the page is accessed.  for a form, drupal_get_form need to be used 
    'page arguments' =&gt; array('video_upload_subtitles_form'), //Name of the Uplaod Form 
    'access callback' =&gt; 'user_access',
    'access arguments' =&gt; array('administer video_subtitles module'),
  );

  $items['player/video_subtitle_status'] = array(
     'page callback' =&gt; 'video_subtitle_status',
     'access callback' =&gt; 'user_access',
     'access arguments' =&gt; array('administer video_subtitles status'),
  );
  return $items;
}

/**
 * Implements hook_permission.
 */
function video_subtitles_permission() {
  return array(
    'administer video_subtitles module' =&gt; array(
      'title' =&gt; t('Administer video_subtitles module'),
      'description' =&gt; t('Access the video_subtitles upload module Page'),
     ),
    'administer video_subtitles status' =&gt; array(
      'title' =&gt; t('Administer video_subtitles module status'),
      'description' =&gt; t('Access the video_subtitles module status Page'),
  ));
}


So User is not able to access my page unless user is logged in, but 
what I need user should be redirected to the login page when he is not logged in as admin , if he successfully login it should be redirected to my page.


visit url d-7/example/my-module 
if already logged in show the page 
if not logged in redirect to the login page 
if user logged in successfully redirect to d-7/example/my-module page


What is best way to achieve this 

Similar Question

using-hook-menu-with-hook-permission-access-denied

using-hook-menu-and-hook-permission-to-control-access 

can-someone-explain-access-arguments-in-drupal
Easiest way will be specifying this logic in page callback function. example:

function SOME_PAGE_CALLBACK($someArg) {
  if(user_is_anonymous()) {
    drupal_goto('PATH_TO_LOGIN_PAGE');
  }

  // do_something();
}


another way is checking the user in hook_preprocess_page function:

function MY_THEME_preprocess_page(&amp;$variables) {
  if(curent_path() == 'SOME_PATH' &amp;&amp; user_is_anonymous()) {
    drupal_goto('PATH_TO_LOGIN_PAGE');
  }
}


Access callback function checks the user's access to the request and returns boolean value, TRUE or FALSE, if you want to check if the user has an access to the page, you can do somthing like this:

$path = current_path();
if ($router_item = menu_get_item($path)) {
  if (!$router_item['access']) {
    drupal_goto('PATH_TO_LOGIN_PAGE');
  }
}