Set a cookie whenever front page is viewed I run a Drupal 7 site (currently 7.15) since longer time and have the problem with cookies:

I need 2 cookies for non-Drupal PHP-scripts at my web site.

I set them in the hook_init of my custom module:

/**
 * Implements hook_user_login().
 */
function pref_user_login(&amp;$edit, $account) {
    if ($account-&gt;uid &lt;= 0) {
      return;
    }

    #drupal_set_message('&lt;p&gt;Hello, '.$account-&gt;name.'&lt;/p&gt;');
    $auth  = md5(join('_', array($account-&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');
}


The problem is, that I need to set the both cookies each time a logged in user visits the front page and not just when the user logs in.

Does anybody please have an idea how to do it, maybe by JavaScript if I can't do it regular way?
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');
  }

}