0

I know this has been answered somewhat but I can't seem to get it work for my specific config. Apologies if this is deemed a duplicate.

I have a cart built in Zend with a button that points to a login page via:

if(!$session->id)
{
  header('Location:'.$fullurl.'login');
}

The button is inside a form by itself. I've tried Arne's suggestion below with no dice. Form code:

<form name="" action="' . $fullurl . 'continue" method="post">
   <input type="submit" name="topay" value="CONTINUE SHOPPING" />
</form>';

How do I get and redirect to the last page visited rather than going to /login?

I've tried doing the old HTTP_REFERER method but couldn't get it to work in Zend.. I understand there's a different method in Zend but can't get it to work from various answers here and here.

Any help is greatly appreciated.

4
  • You can save $_SERVER['HTTP_REFERER'] in session, and after use it while redirect
    – Winston
    Oct 4, 2013 at 17:04
  • Yeah, I tried that but couldn't get it to work within the controller. If you need anything else to help answer, let me know.
    – kettultim
    Oct 4, 2013 at 18:00
  • am sorry for that answer ,actually you may need to save the last visited url in database and redirect ,but i think your logic is wrong because if user is not logged how you know last visit ?please clarify
    – Arun Killu
    Oct 4, 2013 at 18:33
  • No worries. I'm talking about capturing the last page visited on the site, possibly in a cookie? (obviously not able to do so if user disabled cookies or enable do not track). This is uncharted territory for me so I'm vague on how to do this in Zend.
    – kettultim
    Oct 5, 2013 at 0:00

1 Answer 1

1

I would use this:

$url = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
$session = new Zend_Session_Namespace('Namespace');
$session->redirect = $url;

// redirect
$this->_redirect($url, array('prependBase' => false));
1
  • 1
    Sorry but that doesn't seem to be working either.. perhaps I'm not configuring it correctly in my controller. I have a controller that's handling the redirect from the form submit (there's nothing else in the controller). I've entered the form code above.. very basic but not sure what I'm doing wrong here.
    – kettultim
    Oct 5, 2013 at 15:13

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.