When creating a module, where do I set cookies? Drupal 7 newb here.

I am creating a simple module. Basically, this has an admin config form with a message text area. On the front end, that message appears or not depending on the state of a cookie.

My question is: where (in what function) should you set the cookie?

My code is:

/**
 * Implements hook_block_info().
 */
function message_block_info() {
  return [
    'message_block' =&gt; [
      'info' =&gt; t('Message'),
      'cache' =&gt; DRUPAL_CACHE_GLOBAL,
    ],
  ];
}

/**
 * Implements hook_theme().
 */
function message_theme() {
  return [
    'message_block' =&gt; [
      'template' =&gt; 'templates/message-block',
      'variables' =&gt; [
        'config' =&gt; NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_block_view().
 */
function message_block_view($delta = '') {
  if ($delta !== 'message_block') {
    return;
  }

  $config = message_default_settings();
  if (empty($config['alert_message']) || $config['alert_show'] === 0) {
    return;
  }


  $block['content'] = array(
    '#theme' =&gt; 'message_block',
    '#config' =&gt; array(
      'alert_show' =&gt; $config['alert_show'],
      'alert_message' =&gt; filter_xss($config['alert_message']),
      'alert_link' =&gt; filter_xss($config['alert_link']),
    ),
  );

  return $block;
}
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