Set a cookie whenever front page is viewed
You could do this in hook_preprocess_page() and instead of setting a variable, you could do something like this:

function pref_preprocess_page(&amp;$vars) {
  global $user;

  // whatever other preprocess stuff you want to do here

  if ($user-&gt;uid &amp;&amp; drupal_is_front_page()) { 
    $auth  = md5(join('_', array($user-&gt;uid, MY_SECRET)));
    $year  = time() + 60 * 60 * 24 * 30 * 12;
    setcookie('pref_id', $account-&gt;uid, $year, '/', '.preferans.de');
    setcookie('pref_auth', $auth, $year, '/', '.preferans.de');
  }

}