php - Magento - Checking if an Admin and a Customer are logged in -
i have web server magento 1.4.0.1 installed. have web site shares credential it. i've managed check if customer logged in or not (after having changed cookies location in magento), things got complicated when tried figure out if admin logged in. can proper answer first session asked (either customer or admin, second 1 never logged in).
how can have both answers?
here code i'm using test out:
require_once '../app/mage.php'; umask(0) ; mage::app(); // checking customer session mage::getsingleton('core/session', array('name'=>'frontend') ); $session=mage::getsingleton('customer/session', array('name'=>'frontend') ); if ($session->isloggedin()) { echo "customer logged in"; } else { echo "customer not logged in"; } // checking admin session mage::getsingleton('core/session', array('name'=>'adminhtml') ); $adminsession = mage::getsingleton('admin/session', array('name'=>'adminhtml')); if($adminsession->isloggedin()) { echo "admin logged in"; } else { echo "admin not logged in"; }
so code this, admin never logged in. if put part admin first, customer never logged in. seems i'm missing line between 2 requests.
this may same problem unanswered question: magento how check if admin logged in within module controller
this seems popular problem, not find proper solution...
thanks help!
what need switch session data. can following code:
$switchsessionname = 'adminhtml'; $currentsessionid = mage::getsingleton('core/session')->getsessionid(); $currentsessionname = mage::getsingleton('core/session')->getsessionname(); if ($currentsessionid && $currentsessionname && isset($_cookie[$currentsessionname])) { $switchsessionid = $_cookie[$switchsessionname]; $this->_switchsession($switchsessionname, $switchsessionid); $whateverdata = mage::getmodel('mymodule/session')->getwhateverdata(); $this->_switchsession($currentsessionname, $currentsessionid); } protected function _switchsession($namespace, $id = null) { session_write_close(); $globals['_session'] = null; $session = mage::getsingleton('core/session'); if ($id) { $session->setsessionid($id); } $session->start($namespace); }
Comments
Post a Comment