Search This Blog

Friday 27 April 2012

Automatic Customer Login and redirect to home page


Code to autologin the customer by his email address:

<?php
    require_once 'app/Mage.php';
    umask(0);
    Mage::app("default");
    Mage::getSingleton("core/session", array("name" => "frontend"));


    $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getWebsite()->getId());
    $customer->loadByEmail('customer@domain.com');
    Mage::getSingleton('customer/session')->loginById($customer->getId());
    Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl())->sendResponse();

?>

7 comments:

  1. I have been exploring for a little bit for any high-quality articles or blog posts on this sort of house . Exploring in Yahoo I eventually stumbled upon this web site. Reading this info So i am glad to exhibit that I’ve a very good uncanny feeling I discovered exactly what I needed. I such a lot indisputably will make certain to do not fail to remember this web site and provides it a look on a constant basis|regularly.
    Magento tutorials

    ReplyDelete
  2. This code is working perfect in local magento,but when i kept same file in server its not getting logged in.May i know the reason??

    ReplyDelete
  3. Make sure the store code is correct:

    Mage::app("default");

    Here default is the store code

    ReplyDelete
    Replies
    1. Thanks for your reply,I am trying this code outside of magento. Its redirecting to home page but user is not getting logged in.Is it related session ?

      Delete
  4. i am calling this code from the cakePHP website but not working....

    ReplyDelete
  5. IT's woking i have created autologin.php file in the magento and call this code....

    Thank you

    ReplyDelete