How to force Drupal to redirect if it doesn't work

180 views
Skip to first unread message

kenorb

unread,
Nov 29, 2010, 5:32:56 AM11/29/10
to drupal-hackers
Sometimes successful redirection depends on destination variable,
weight of modules, etc.
Sometimes you don't know if you want to use $form_state['redirect']
and where, because <a href="http://drupal.org/node/482696">simply it
doesn't work</a>.
Sometimes you don't want to use drupal_goto, because it redirect
straight away ignoring other module, which are required to execute the
code and re-save the proper permissions, etc.
Using drupal_goto into hook_exit doesn't work, or you have to
duplicate complex condition to check if you want to redirect, but it
looks ugly and wrong.
Does this sound familiar to you?

Simple solution:
register_shutdown_function('drupal_goto', 'node');

It's executed always after Drupal finished all the processing.
If you need do the redirect at start, use hook_init()
Reply all
Reply to author
Forward
0 new messages