I have created a custom module in which when a user enters a valid id, it should them take them to an external website. The problem I am having is redirecting to the external website. The code I am using in my module is to do the redirection is:

  // clear out the output buffer
  while (ob_get_status()) {
  return header("Location: $external_url");

This doesn't work. What should I be using to accomplish this?


2 Answers 2


You should use drupal_goto to redirect to a URL.

drupal_goto($external_url, array('referral' => $referral_url));

You should use drupal_goto()

This question is answered in more detail here:

What API function do I use for redirecting to external URLs?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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