Wednesday, August 11, 2010

Check if user is logged-in in Magento backend



This code snippet will check if a user is currently logged-in on magento backend.. this is useful if you want to integrate pages to your magento website, of course you must check if the user that is accessing the said page is an authenticated user of your magento administration.. that is where this code comes into play.. hope this helps

require_once '../app/Mage.php';
umask(0);

$app = Mage::app('default');

/* Init User Session */
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
$session = Mage::getSingleton('admin/session');

if ($session->isLoggedIn()) {

/* do something if logged in */
echo "the user is logged in";

} else {
/* do something else if not logged in */
echo "the user is NOT logged in";
}

?>

1 comment:

  1. Great!!! it work.

    i created the gist: https://gist.github.com/jruzafa/9233299

    ReplyDelete