When creating a module, where do I set cookies?
Here i set the cookie as user login and logged out.

/**
 * Implements hook_user_login().
 */
function HOOK_user_login(&amp;$edit, $account) {
  setcookie('user-logged-in', '2', 0, '/');
}

/**
 * Implements hook_user_logout().
 */
function HOOK_user_logout($account) {
  // Set cookie in the past and then remove it.
  setcookie('user-logged-in', '', REQUEST_TIME - 3600, '/');
  unset($_COOKIE['user-logged-in']);
}


You can try it will able to create new cookie anywhere i.e Create cookie into  hook_init() 
https://www.drupal.org/forum/support/theme-development/2009-05-26/setting-custom-cookies#comment-2901778