hook_file_dowload() randomly thinks user is anonymous I have a custom module implementing hook_file_download() for both public and privately managed files. At the head of my hook implementation I have the typical declarations to access the $user global:

function contractor_file_download( $uri ) {
  $caller = 'contractor_file_download';
  global $user;

  devlog( $caller.': uri is "'.$uri.'", user is "'.$user-&gt;uid.'"' );
  devlog( $caller.': globals user is "'.print_r( $GLOBALS['user'], 1 ).'"' );
  ...
}


The problem I'm having is that $user contains the anonymous user sometimes, if that makes any sense. Although it makes no sense, when testing via an OSX machine, any browser, the $user is always the valid logged in user. But when testing via any flavor of Windows, about 70% of the time both $user and $GLOBALS['user'] both contain the anonymous user. Yet, in all instances, the "My Account" link can be clicked and the correct logged in user profile loads.

What could cause $user to contain the anonymous user even after the user has logged in? 

Additional info: the files being accessed getting the anonymous user are all private managed files.
Solution is insuring all site urls use the same subdomain, either including the www before the domain or not including the www before the site domain. Plus within .htaccess forcing all user urls to reference the site via that same subdomain qualifier. 

The problem was inconsistent use of www and nothing as the site's subdomain.