Magento : Check If Admin Is Logged In Or Not In Frontend

It is a dirty way and not a clean code.
To check the magento admin user is logged in or not in admin panel, you can use following custom php script to check in/from frontend.
You can also use this code in controller, helper, model or phtml files for the same checking.
<?php
define('MAGENTO_ROOT', getcwd());
require_once MAGENTO_ROOT . '/app/Mage.php';
$sessionId = isset($_COOKIE['adminhtml']) ? $_COOKIE['adminhtml'] : false;
$session = false;
if ($sessionId) {
    $session = Mage::getSingleton('core/resource_session')->read($sessionId);
}
$loggedInFlag = false;
if ($session) {
    if (stristr($session, 'Mage_Admin_Model_User')) {
        $loggedInFlag = true;
    }
}
var_dump($loggedInFlag);
exit;
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s