Magento: Redirect back to page after logged-in in Magento

by mageefy on Apr 12, 2023 Celebrities 340 Views

If you need to go back to same page once it logged in then in list page and clicked to sign in link and then you logged in it has to go back to list page its self

Magento has default setting for not to redirect account page if you logged in from default page by default it will redirect to account dash board but you need to go page to list page for that follow the below steps--

Open header.phtml add this code at top of the file

[php]

if(!Mage::helper('customer')->isLoggedIn()) {
$loginback=$this->helper('core/url')->getCurrentUrl();
$check=strstr($loginback, 'customer/account/login');
if(!strlen($check)){
Mage::getSingleton('core/session')->setLoginBackUrl($loginback);
}
}

[/php]

override app\code\core\Mage\Customer\controllers\AccountController.php to you local or custom module and add this function

[php]

public function _loginPostRedirect()
{
$session = $this->_getSession();

if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl()) {

// Set default URL to redirect customer to
$session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());
// Redirect customer to the last page visited after logging in
if ($session->isLoggedIn()) {
$backUrlcustom=Mage::getSingleton('core/session')->getLoginBackUrl();
if (!Mage::getStoreConfigFlag('customer/startup/redirect_dashboard')) {
$referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
if ($referer) {
$referer = Mage::helper('core')->urlDecode($referer);
if ($this->_isUrlInternal($referer)) {
$session->setBeforeAuthUrl($referer);
}
}
} else if ($session->getAfterAuthUrl()) {
$session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
} else if (strlen($backUrlcustom)) {
Mage::getSingleton('core/session')->setLoginBackUrl('');
$session->setBeforeAuthUrl($backUrlcustom);
}
} else {
$session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl());
}
} else if ($session->getBeforeAuthUrl() == Mage::helper('customer')->getLogoutUrl()) {
$session->setBeforeAuthUrl(Mage::helper('customer')->getDashboardUrl());
} else {
if (!$session->getAfterAuthUrl()) {
$session->setAfterAuthUrl($session->getBeforeAuthUrl());
}
if ($session->isLoggedIn()) {
$session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
}
}
$this->_redirectUrl($session->getBeforeAuthUrl(true));
}

[/php]

Article source: https://article-realm.com/article/Arts-Entertainment/Celebrities/42138-Magento-Redirect-back-to-page-after-logged-in-in-Magento.html

Comments

No comments have been left here yet. Be the first who will do it.
Safety

captchaPlease input letters you see on the image.
Click on image to redraw.

Reviews

Guest

Overall Rating:

Most Viewed Articles

Statistics

Members
Members: 16849
Publishing
Articles: 78,779
Categories: 202
Online
Active Users: 3260
Members: 16
Guests: 3244
Bots: 32375
Visits last 24h (live): 5512
Visits last 24h (bots): 58054

Latest Comments

Nice Post Good Work Mumbai
on Aug 11, 2026 about Activating Peacock TV on Fire TV:
Experience the joy of eggy car , where every level presents a new challenge! Navigate through tricky paths and keep your egg intact. With its simple controls and addictive gameplay, Eggy Car is...
Besides these intense study and training sessions, if you need a lighthearted form of management and constructive entertainment, a fun simulation game like monkey mart would certainly...
The discreet professionalism of Escorts Ito ensures your private moments remain your own, allowing you to fully immerse yourself in the pleasure of their company.  
Thanks for sharing 
on Aug 11, 2026 about Patricklamma
I really enjoyed going through your collection of articles. You have covered a wide range of useful topics, and the consistency of your writing shows genuine effort and knowledge. I especially...
on Aug 11, 2026 about Dr. Sam Khoury
A well-designed home also benefits from the right flooring and décor. TheRugShopUK offers rugs in various styles and sizes that can add comfort, warmth, and character to granny flats, bedrooms,...
Quordle is like Wordle on steroids! Solving four words at once is a fun challenge that keeps me focused.
Last weekend in Dwarka I finally decided to try something different and it was worth every rupee. The experience with VIP Dwarka Escorts felt genuinely premium, from the conversation to the...

Translate To: