Is there a drupal hook that I can use to redirect a user to an interstitial page for the first page view? If not then how can I accomplish this? I am currently in the process of developing a custom module that will redirect a user on entry to an interstitial landing page.  This page will closely replicate how forbes.com functions.  The landing page itself is a page template within the custom module that displays a view, an ad, and links back to the originally requested page. All of the pieces are in place and function as intended except for the hook when caching is enabled. After researching hook_boot, hook_init, and hook_page_alter, I have found that none of these are working when caching is turned on or in the case of hook_boot because drupal functions were not loaded when the hook was called.  I feel hook_boot is the closest solution at this point but after reading the comments in the api it was said that you shouldn't invoke any drupal modules inside of that hook. Is there a way I can detect if the user is anon without user_is_anonymous()? Should I write this hook without any drupal functions? Should I bootstrap drupal in hook_boot similar to how its done in the core module file statistics/staticstics.php?  

Here is my code for hook_boot:

function my_module_boot() {
  // If anon proceed
  if(user_is_anonymous()){
    if(isset($_COOKIE['welcome_page'])){
      // do nothing
    } else {
      $cookie = filter_xss($_COOKIE['welcome_page']);
      // If user saw welcome page and has cookie- skip redirect
      if($cookie != 1) {
        setcookie('welcome_page', 1, time()+86400);
        $destination = drupal_get_destination();
        drupal_goto('welcome', array('query'=&gt;$destination), $http_response_header = 301);
      }
    }
  }
}


My goal is to keep all of the code contained inside of the module. I'd rather not use any other contrib module at this point because my module is close to completion. This redirect should only get triggered if the user does not have the cookie and is anon.  Finally I do not want the site to appear before the landing page.

Thanks for any help.

Solution:

function my_module_boot() {

  if(isset($_COOKIE['welcome_page']) || isset($_COOKIE['welcome_page_admin'])) {
    // do nothing
  } else {
    $cookie = filter_var($_COOKIE['welcome_page'], FILTER_SANITIZE_STRING);
    // If user saw welcome page and has cookie- skip redirect
    if($cookie != 1) {
      $destination = '/';
      if($_GET['q']) {
        // Microtime for IE9 to properly redirect
        $destination = $_GET['q'] . '?a=' . microtime(true);
      }
      // Redirect and set cookie
      setcookie('welcome_page', 1, time()+86400);
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: /welcome?destination=" . $destination);
      exit();
    }
  }

}

function my_module_user_login(&amp;$edit, $account) {

  // Expires in one year for authenticated
  setcookie('welcome_page_admin', 1, time()+31556926);

}
Your suspicions are correct. If you want to do this server side on a cached page, you'll need to use hook_boot() and you won't be able call most Drupal functions because Drupal hasn't been bootstrapped at the stage that hook_boot() runs.

It seems to me that this is much better suited to client side. I would move this to a small js file (put it in the head if you're worried about the the redirect happening too late).