user not logged in php file
This forum post on d.o explains what may be your problem.

You need to: 


  Set $cookie_domain='example.com'; explicitly in your settings.php file. 


According to the post, Drupal keeps a long session ID string in a cookie, and without a proper cookie domain, the current user is anonymous.