0

How can we get the second last url in Magento 1.9?

I currently use this: <?php echo Mage::getSingleton('core/session')->getLastUrl();?> To get the last URL.

But I want to get the second last URL after adding a product to the cart. Because the code above give in that case the url to add the product to the cart.

How can I get the url before that, so the second last?

1

You can use

Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER']);

to get the second last URL or Referrer URL. Or if you need it as a string

Mage::app()->getResponse()->setRedirect($_SERVER['HTTP_REFERER'])->getHeaders()[2]['value'];

$_SERVER['HTTP_REFERER'] would output the url or you may use

$previousurl = Mage::helper('core/http')->getHttpReferer() ? Mage::helper('core/http')->getHttpReferer()  : Mage::getUrl();
  • Thanks! But that does already set a redirect. I need only the URL. – Henk Z Dec 27 '18 at 11:42
  • Thanks again! I thought it worked well, but it seems that the previous url is wrong. It looks like is is being cached into Cloudflare. Any idea? – Henk Z Dec 27 '18 at 15:17
  • You can try deleting Cloudflare cache support.cloudflare.com/hc/en-us/articles/… followed by flushing Magento cache storage. – Kumar A. Dec 28 '18 at 7:39

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.