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

by mageefy on Apr 12, 2023 Celebrities 379 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: 17266
Publishing
Articles: 79,974
Categories: 202
Online
Active Users: 1214
Members: 3
Guests: 1211
Bots: 7810
Visits last 24h (live): 5209
Visits last 24h (bots): 36585

Latest Comments

Short and simple explanations are sometimes easier to follow than long articles.  카지노 방송
on Nov 5, 2026 about The Latest Online Business
Comparing information from different sources made the overall process much easier to understand.  프라그티비 평생도메인
on Nov 5, 2026 about The Latest Online Business
I honestly thought every gift card worked the same, but there are more differences than I expected.  상품권 카드 구매  
on Nov 5, 2026 about The Latest Online Business
Embarking on a peaceful yoga and Ayurveda retreat in India sounds like the ultimate way to achieve complete inner peace, stress relief, and total mental clarity. Too bad all that inner calm gets...
Finding a detailed global market report on recombinant cell culture supplements hidden away in a music directory is a wild plot twist, it almost as abrupt as running head-first into a sudden spike...
Exploring the majestic forts and royal history of India sounds like an incredible journey through timeless architecture. Too bad no amount of royal heritage can help you master the chaotic,...
This blog really convinced me to do it! Thanks, very good post  Jpbosku    
This blog really convinced me to do it! Thanks, very good post  Jpbosku    
Thanks for sharing these informations. I really like your blog post very much. You have really shared a informative and interesting blog post .    pakde4d    
I love the way you write and share your niche! Very interesting and different!    pakde4d    

Translate To: