Thứ Hai, 29 tháng 11, 2010

How to Create Custom login Session in magento

If you are trying to make a custom login module in magento then Magento have a default functionality to make a Custom login session,Which destroy automattically after some time, if you will be Inactive for a moment.


Here I am showing you How to set login session value and How to get login session value.



$username=$this->getRequest()->getParam('username');

$password=$this->getRequest()->getParam('password');

$sql='select * from `tablename` where `username`= "'.$username.'" and `password`="'.$password.'" ';

$read = Mage::getSingleton('core/resource')->getConnection('core_read');

$row = $read->fetchAll($sql);

if($row)

{

Mage::getSingleton('core/session')->setlogin($row[0]['username']);

$this->_redirect('customer/account/index/');

}


Now You have Logged in to your account. If you want to retrive login Session value then you need to write the following code



$login = Mage::getSingleton('core/session')->getlogin();

if($login)

{

$this->loadLayout();

$this->renderLayout();

}

Không có nhận xét nào:

Đăng nhận xét