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

2 comments:

  1. Anonymous12/08/2010

    Hi Anjan,
    Im trying to make 2 magento sites work with one single login. For example if a client logs in to one site, he should be able to buy on the other.
    Can you tell me if something like this can be done without destroying magentos integrity?
    Thank you.
    Phil

    ReplyDelete
  2. looking to store simple variable data to the session, working out!

    ReplyDelete