I am trying to save a $_GET value in my custom session by using observer.

So I have this method that fires on custom_front_init_before

public function checkLocationId() {
  $location = Mage::app()->getRequest()->getParam('location');
  if(!empty($location)) {
    if (strlen($location) > 15) return;
    $location = (int) $location;

When I visit www.mymagentostoreaddress.com/?location=234 value 234 is saved in session. Once I click on any other link on the page Magento starts a new session (session_id changes) and my value is no longer available.

Why Magento starts a new session and how can I fix this? Or maybe you have suggestions what to test to find out what's happening? I'd appreciate your input.


Calling the same code from header.phtml saves the value to a session and it doesn't get reinitialized on reload. This leads me to a conclusion that perhaps I've attached it to incorrect event.

So now I'm looking for an event that gets called on every page just before template files get processed.


Like you suspect, most probably you are using an event that is dispatched before the session is initialized.
if you need to do your verification for every page then use controller_action_predispatch. If you need to do the verification for a specific action use controller_action_predispatch_[module]_[controller]_[action].

  • Yes, this was the source of the problem. Thanks for the event. – Alan Feb 16 '15 at 7:33

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.