How to Create Custom login Session in magento

piaoling  2011-07-14 18:57:54

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();
}

类别 :  magento(258)  |  浏览(3382)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: