Pre-process drupal_goto or use hook_exit to stop redirect I want to unit test some drupal custom modules but the drupal_goto() function is causing problems by creating header errors (e.g.: PHP Warning:  session_start(): Cannot send session cookie).

My question is, is it possible to stop the drupal_goto() function from redirecting to the destination page or somehow tap into hook_exit() to return the $destination.

I've tried something like (in addition to exit and die, but it stops the PHPUnit tests:

function custommodule_exit( $destination = null ) {
  return $destination;
}


Any help is appreciated.
This is most often caused by UTF-8 with BOM. Check your editor and change the file format if it is.

The only way to redirect in hook_exit() is another drupal_goto(). Be careful that you don't create redirection loops.