$GLOBALS['user']->uid returns same uid for different logged in users? I'm implementing hook_menu in my custom module. Implementation works fine except, it turns out that $GLOBALS['user']->uid returns always same value no matter which user is currently logged in. Sounds absurd! What could be the problem?

Below is a full hook_menu:

function my_tab_menu(){

    $current_user_id = $GLOBALS['user']-&gt;uid;  // $current_user_id=202 for each 

    $query = new EntityFieldQuery();
        $result = $query
                -&gt;entityCondition('entity_type', 'node')
                -&gt;entityCondition('bundle', 'profile')
                -&gt;propertyCondition('status', 1)
                -&gt;propertyCondition('uid', $current_user_id)
                -&gt;propertyOrderBy('created', 'DESC')    
                -&gt;range(0,1)
                -&gt;execute();



    if (isset($result['node'])) {
        return array(
        'user/%/alumni-spotlight' =&gt; array(
                'title' =&gt; 'Alumni spotlight',
                'page callback' =&gt; 'user_tab_page',
                'page arguments' =&gt; array(1,$result['node'],$current_user_id),
                'access callback' =&gt; 'user_tab_access',
                'access arguments' =&gt; array(1),
                'type' =&gt; MENU_LOCAL_TASK,
            ),
           );
    }
}
Hook menu is not for non-menu functionality.

Using %user in the menu item will call user_load() with whatever is in that part of the url (in this case the uid) and then when that part of the url is used in callback or access arguments it will pass in the loaded user object instead of the user id.

See wildcard loader arguments for more info on that.

To control who sees the tab, do your database check in the access control callback and deny access if there is no result. This way the tab will only show if there is a node.

Callbacks like the access control call back and the title callback run every time, not just when the cache is refreshed, so it is ok to use them in this way.

Try

/**
 * Implements hook_menu().
 */
function MYMODULE_menu() {
  $items = array();

  $items['user/%user/alumni-spotlight'] = array(
    'title' =&gt; t('Alumni spotlight'),
    'page callback' =&gt; 'MYMODULE_user_tab_page',
    'page arguments' =&gt; array(1),
    'access callback' =&gt; 'MYMODULE_user_tab_access',
    'access arguments' =&gt; array(1),
    'type' =&gt; MENU_LOCAL_TASK,
  );

  return $items;
}

/**
 * Access callback for user alumni spotlight page.
 */
function MYMODULE_user_tab_access($user) {
  // Do something here to check access &amp; return TRUE or FALSE to grant access or not.
  $query = new EntityFieldQuery();
  $result = $query
    -&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', 'profile')
    -&gt;propertyCondition('status', 1)
    -&gt;propertyCondition('uid', $user-&gt;id)
    -&gt;propertyOrderBy('created', 'DESC')    
    -&gt;range(0, 1)
    -&gt;execute();

  // If there is a node, allow the user to access the page.
  if (isset($result['node'])) {
    return TRUE;
  }

  // If there is no node, deny access.
  return FALSE;
}

/**
 * Page callback for user alumni spotlight page.
 */
function MYMODULE_user_tab_page($user) {
  // Return the content of the page.
}