Skip to content

Mukesh Chapagain Blog

  • PHP
    • PHP
    • Laravel
    • WordPress
    • Joomla
  • Magento
    • Magento 2
    • Magento Extension
  • Node.js
    • Node.js
    • Javascript
    • jQuery
  • Database
    • MySQL
    • MongoDB
  • Data Science
    • Machine Learning
    • Recommender System
    • Natural Language Processing (NLP)
    • Sentiment Analysis
    • Python
    • R
  • Categories
    • Blockchain
      • Hyperledger Composer
      • Hyperledger-Fabric
    • Other
      • Cryptography
      • Data Structures & Algorithms
      • Git
      • LaTeX
      • Linux
      • Ubuntu
      • Xubuntu
      • Google
      • Google AppScript
  • About
    • About
    • Contact
    • Privacy Policy

Home » Magento » Magento: Redirect Customer to Previous Page After Login

Magento: Redirect Customer to Previous Page After Login

August 19, 2014 by Mukesh Chapagain
Categories Magento Tags customer, login, Magento, redirect
FacebookTweetLinkedInPinPrintEmailShares

By default, customers are redirected to ‘Customer Account Dashboard’ page after login. This feature can be easily changed from Magento configuration settings.

Configuration Settings

– Login to admin panel
– Go to System -> Configuration -> CUSTOMERS -> Customer Configuration -> Login Options
– Set: Redirect Customers to Account Dashboard after Loggin in = No
– You can see in comments for this field: Customer will stay on the current page if “No” is selected.

This setting will redirect customers to the page from where they have come to login page. This setting is applicable for all pages of your Magento website.

You might have another condition of having this feature only on some specific pages. For example, you might want this feature only on product view page. Or, you might have a category that is visible to logged in customers only. In this case, you can simply use the following code:

Redirect to customer login page


if(!Mage::helper('customer')->isLoggedIn()) {
	Mage::getSingleton('customer/session')
            ->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl()); 
	$this->_redirect('customer/account/login');
}

Show a login link for non-logged in customers


if(!Mage::helper('customer')->isLoggedIn()) {
	Mage::getSingleton('customer/session')
            ->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl()); 
	echo '<p>Please <a href="'.Mage::getUrl('customer/account/login').'">Login</a> to view the page.</p>';
}

Customers will be redirected to previous page after successful login.

Hope it helps. Thanks.

Related posts:

  1. Magento: Redirect Customer to Login page if not logged in
  2. Magento: Create Customer Programmatically
  3. Magento: Add new tab to Customer Account Section
  4. Magento: Send confirmation email on new customer registration
Categories Magento Tags customer, login, Magento, redirect
Magento: Check if a module is installed, enabled or active
Magento: Clear / Delete Shopping Cart Items of Single or All Customers

About

Mukesh Chapagain Hi, I’m Mukesh Chapagain — a web developer, programmer, and tech enthusiast. Whether you're a beginner or an experienced developer, you’ll find tips, tutorials, and insights to help you navigate the ever-evolving world of technology. Happy coding! 🚀 about...

         

Subscribe via Email



Categories

Most Viewed

  • How to Calculate Inverter & Battery Backup Time? - 428,020 views
  • Very Simple Add, Edit, Delete, View (CRUD) in PHP & MySQL [Beginner Tutorial] - 415,656 views
  • LaTeX: Generate dummy text (lorem ipsum) in your document - 228,050 views
  • GPG: Remove keys from your public keyring? - 201,573 views
  • Magento: How to get attribute name and value? - 188,264 views

Recent Posts

  • Magento: The store that was requested wasn’t found. Verify the store and try again.
  • Magento2: Check Services version on Adobe Cloud Server
  • Magento 2 API: Add Products to Cart & Checkout Place Order
  • Magento 2 API: Create New Customer
  • Magento 2 API: Get Categories

Recent Posts

  • Magento: The store that was requested wasn’t found. Verify the store and try again.
  • Magento2: Check Services version on Adobe Cloud Server
  • Magento 2 API: Add Products to Cart & Checkout Place Order
  • Magento 2 API: Create New Customer
  • Magento 2 API: Get Categories

Most Viewed

  • How to Calculate Inverter & Battery Backup Time? - 428,020 views
  • Very Simple Add, Edit, Delete, View (CRUD) in PHP & MySQL [Beginner Tutorial] - 415,656 views
  • LaTeX: Generate dummy text (lorem ipsum) in your document - 228,050 views
  • GPG: Remove keys from your public keyring? - 201,573 views
  • Magento: How to get attribute name and value? - 188,264 views

Tag Cloud

admin Adobe Commerce api array attribute block category checkout CLI command line crud currency customer Database error extension git Google grid HTML image Javascript Joomla jQuery latex Linux login Magento magento2 magento 2 module MySQL natural language processing NLP nltk nodejs order PHP product python shopping cart template Ubuntu url Wordpress
© 2025 Mukesh Chapagain Blog
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkPrivacy policy