3

When I am trying to call drupal_goto from hook_boot I get an error:

Fatal error: Call to undefined function drupal_goto()

What am I doing wrong and why is that happening?

My code:

function custom_mobile_redirect_boot() {
  include_once 'Mobile_Detect.php';
  $detect = new Mobile_Detect();
  if ($detect->isMobile() || $detect->isTablet()) {
    drupal_goto('http://testsite.local');
  }
}
8

In hook_boot() lot of APIs will not work as the required function definitions for them will not be loaded. In this case common.inc where drupal_goto() is defined is not yet included ergo you get that error. If its not possible to use hook_init() make use of Header. Check out mobile_tools module hook_boot() for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.