php - Magento login a customer programmatically -
i trying login customer programmatically in magento. have followed this tutorial.
so created file named test.php in root of magento app.
<?php require_once 'app/mage.php'; function loginbyid($customerid) { mage::app(); // make sure mage::getmodel() works $customer = mage::getmodel('customer/customer')->load($customerid); if ($customer->getwebsiteid()) { mage::init($customer->getwebsiteid(), 'website'); $session = mage::getsingleton('customer/session'); $session->loginbyid($customerid); return $session; } throw new exception('login failed'); } try { $session = loginbyid(1); //echo mage_customer_model_session::isloggedin();exit; // var_dump($session);exit; // function login() above $session->setafterauthurl( 'http://192.168.1.61/magento/index.php/customer/account'); //echo $session->getafterauthurl();exit; header('location: ' . $session->getafterauthurl()); } catch (mage_core_exception $e) { echo "error"; } but when access file, redirect me login form.
try one
<?php function loginuser( $email, $password ) require_once ("app/mage.php"); umask(0); ob_start(); session_start(); mage::app('default'); mage::getsingleton("core/session", array("name" => "frontend")); $websiteid = mage::app()->getwebsite()->getid(); $store = mage::app()->getstore(); $customer = mage::getmodel("customer/customer"); $customer->website_id = $websiteid; $customer->setstore($store); try { $customer->loadbyemail($email); $session = mage::getsingleton('customer/session')->setcustomerasloggedin($customer); $session->login($email, $password); }catch(exception $e){ } } ?>
Comments
Post a Comment