1

Is it possible to reload same page on successful logout in magento. Currently it will redirect to home page after redirecting to the page that says you will be redirected to home page in 5 secs.

This is from AccountController- logoutSuccessAction.

SMALL EDIT IN THE LOGIC I NEED

After going to the intermediate page (you have logged out and you will be re directed to home page in 10 seconds) only I need to redirect the user to page previous to the intermediate page.

If the current page is https then I want the user to be re directed to home page.

4 Answers 4

2

As you want to go back to last page after logout.

Then you need Override to AccoutController.php 's logoutAction.

In magento,you can get Referer Url at any controller using function _getRefererUrl().

Now using _redirectUrl() redirect to this page.

<?php 
require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
class [ModuleNameSpace]_[ModuleName]_AccountController extends Mage_Customer_AccountController{
 public function logoutAction()
    {
        $session = $this->_getSession();
        $session->logout()->renewSession();
        if(!$session->getBeforeAuthUrl()){
        $session->setBeforeAuthUrl($this->_getRefererUrl());
    }

    $this->_redirectUrl($session->getBeforeAuthUrl(true))
    }
6
  • This is not getting me back to same page instead login page :(
    – Swetha
    Sep 28, 2015 at 9:34
  • Have you tried to logout from list or product page? what result will occure?
    – Amit Bera
    Sep 28, 2015 at 9:38
  • sss i tried and its taking me to home page once and den login page once.. quite inconsistent :(
    – Swetha
    Sep 28, 2015 at 9:39
  • i had add something ,,please hcekc
    – Amit Bera
    Sep 28, 2015 at 9:43
  • I think this will take me to the page where i was before logging in.. not the current page
    – Swetha
    Sep 28, 2015 at 9:52
1

You may be able to just set the flag under System > Configuration > Customers > Customer Configuration: Redirect Customer to Account Dashboard after Logging in. Setting this also seems to affect Logout:

const XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD = 'customer/startup/redirect_dashboard';


    /**
     * Customer logout action
     */
    public function logoutAction()
    {
        $session = $this->_getSession();
        $session->logout()->renewSession();
        if (Mage::getStoreConfigFlag(Mage_Customer_Helper_Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD)) {
            $session->setBeforeAuthUrl(Mage::getBaseUrl());
        } else {
            $session->setBeforeAuthUrl($this->_getRefererUrl());
        }
        $this->_redirect('*/*/logoutSuccess');
    }
1

You can find the logout.phtml file from app/design/frontend/base/default/template/customer/logout.phtml make copy and modify that file to your own theme directory.

setTimeout(function(){ location.href = '<?php echo $this->getUrl() ?>'},5000);

you can modify to <?php echo $this->getUrl('*/ logout */') ?>

2
  • I dont wanna redirect to logout.phtml at all.. I jus wannt renew the session in the same page itself.
    – Swetha
    Sep 26, 2015 at 14:16
  • you can use this $this->renewSession(); Sep 26, 2015 at 14:19
0

1)app/etc/modules/AK_Logoutredirect.xml

<config>
    <modules>
        <AK_Logoutredirect>
            <active>true</active>
            <codePool>local</codePool>
        </AK_Logoutredirect>
    </modules>
</config> 

2)app/code/local/AK/Logoutredirect/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <AK_Logoutredirect>
            <version>1.0</version>
        </AK_Logoutredirect>
    </modules>  
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <ak_logoutredirect before="Mage_Customer">AK_Logoutredirect</ak_logoutredirect>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend> 
</config> 

3)app/code/local/AK/Logoutredirect/controllers/AccountController.php

<?php

require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
class AK_Logoutredirect_AccountController extends Mage_Customer_AccountController{

     public function logoutAction(){
        $session = $this->_getSession();
        $session->logout()->renewSession();
        if(!$session->getBeforeAuthUrl()){
        $session->setBeforeAuthUrl($this->_getRefererUrl());        
        }
         $this->_redirectUrl($session->getBeforeAuthUrl(true));
      }

}  

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.