1

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.

1
  • Is working if i use $laastUrlString = $lastUrl->getHeaders()[2]['value']; Commented Jul 19, 2016 at 7:15

2 Answers 2

3

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);
Sign up to request clarification or add additional context in comments.

4 Comments

yes, i know that, but i need the url as a string, because i wanna modify the previous url. is work if i use $laastUrlString = $lastUrl->getHeaders()[2]['value'];
this Mage::helper('core/http')->getHttpReferer() it give me large array
You can get URL from array. if not send me array file.
$response = Mage::app()->getFrontController()->getResponse(); $response->setRedirect($url); you can use this code instead that.
1

Use this in your controller:

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.