I want to convert an existing site to support the selection and association of Cities. Each node can be associated with a City, and the Cities will be selectable as tabs at the top of each page.

Lets say the City Taxonomy is:

  • All Cities (mainly used for old content the client doesn't want to convert)
  • London
  • New York
  • Paris

If a user browses to any City's front page then that will stamp that city in their cookie/user profile, such as:

  • site.com/all-cities
  • site.com/london
  • site.com/new-york
  • site.com/paris

Then when the user returns to the site front page site.com/ without a city specified, they'll be redirected to their remembered front page.

The site does not support user accounts however, so only anonymous users will visit, so it only needs to use cookies rather than store data in the DB per user.

Importantly, on top of this, the site is using 1 hour page caching due to relatively low traffic and poor page load speeds, so the redirect will need to run before the cache.

What is there a standard Drupal way to achieve the above, or will it need to be entirely custom in order to run outside any form of caching?

Thanks for any advice!

1 Answer 1


I would create a custom module and.

  1. Save the choice in the users session (sessions is mapped to a cookie)
  2. Use hook_boot to do the redirect, a simple drupal_goto should be enough.

Using sessions is more simple, but depending on your settings the data will persist for a shorter period of time than cookies. But that might be a good thing.

  • Hmm it seems that drupal_goto is not defined when hook_boot runs, so I'll need to fall back to header() I guess.
    – DanH
    Commented Jun 8, 2011 at 8:45
  • 1
    @DanH You can include the file where it's defined.
    – googletorp
    Commented Jun 8, 2011 at 9:22
  • Remember that hook_boot means that the module is incompatible with aggressive caching. Just a heads up. Commented Jun 9, 2011 at 10:21

Your Answer

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

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