Anonymous sessions breaking login for Drupal 7
If you are actually trying to override the default behaviour of assigning uid, you need to explain why. In order to access the already determined uid information created by Drupal, use this in template.php or a .tpl.php:

&lt;?php
  global $user;
?&gt;


To see what information is already available in $user, make use of the Devel Module:


  Helper functions for Drupal developers and inquisitive admins. This
  module can print a summary of all database queries for each page
  request at the bottom of each page. The summary includes how many
  times each query was executed on a page (shouldn't run same query
  multiple times), and how long each query took (short is good - use
  cache for complex queries).


specifically, the dpm() function.  This can be added just about anywhere as:

&lt;?
  php global $user;
  dpm($user);
?&gt;


This will present a breakdown of the $user array and all the information it contains.