I have installed Drupal 6 and working on custom module.

I want to redirect all user request to a confirmation page when he try to access any other URL. The flaw is :

  1. User login
  2. If user status is set get confirm set a session variable and re-direct to another page
  3. Confirm or cancel
  4. When ever user try to access any other page show the confirmation page

I have an issue when user do not select any option and type the URL and go to another page. Then I want to check the session variable and redirect the user to confirmation page.

I tried with Drupal hook_init function implementation on my custom module but it gives a redirect loop.

function customprints_init() {

    if ( $_SESSION['show_print_size_confirm'] && $_REQUEST['q'] != 'print/confirm/size' ) {

I can not do the check in template files as there are about 50 template files.

Is there a way to do this properly in a hook function or in a common place.

  • Why do you need to use this expensive hook_init hook at first place ? There are different methods to redirect upon login, form submission, etc. I'd suggest you to use one of them instead. – AyeshK Feb 7 '13 at 9:48
  • @AyeshK, I want to redirect user to an specific confirmation page whenever he access other pages without confirming. The condition is set based on user status. – Shantha Kumara Feb 8 '13 at 4:46
  • longshot conjecture here, but give $_GET['q'] != 'print/confirm/size' instead of $_REQUEST['q'] != 'print/confirm/size' a shot as I've done almost exactly what you've done here without getting any redirect loops. If that doesn't work, also check to make sure print/confirm/size is an actual drupal system path and not an alias, eg, node/# vs pretty/path/to/content. – Jimajamma Feb 12 '13 at 16:11
  • @Jimajamma Thanks but still redirect loop. The path 'print/confirm/size' is a path specified as an item in hook_menu implementation. – Shantha Kumara Feb 13 '13 at 8:19

Your Answer

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

Browse other questions tagged or ask your own question.