RedoColor
RedoColor

Reputation: 145

get previous url in magento as a string

I try to obtain last/previous URL and I can't get like an URL.

Here is my code:

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

And I try extract the URL from this array, but it give me this error:

Cannot use object of type Mage_Core_Controller_Response_Http as array

using: var_dump($lastUrl['value'])

Or null if I try $lastUrl->value

How I can extract the URL as a string? I always have trouble with this arrays.

Upvotes: 1

Views: 10610

Answers (2)

leogent
leogent

Reputation: 56

Use this in your controller:

$lastUrl = $this->_getRefererUrl();
echo $lastUrl; exit;

Upvotes: 1

Sunny Rathod
Sunny Rathod

Reputation: 508

You can use below code for referer URL get and redirect to that URL

$url = Mage::helper('core/http')->getHttpReferer() ? Mage::helper('core/http')->getHttpReferer()  : Mage::getUrl();
Mage::app()->getResponse()->setRedirect($url);

Upvotes: 3

Related Questions