I have this code, found on the Internet, to check if a user is logged on to the admin pages or not.

I recently installed Redis Session Cache successfully, and now these lines of code doesn't work anymore.

Anyone know if it's possible to change this, to get it to work when storing sessions in Redis?

Thanks in advance,

require $_SERVER['DOCUMENT_ROOT'] . "/app/Mage.php";

function isBackendUserLoggedIn() {
    if (!array_key_exists('adminhtml', $_COOKIE)) return false;

    if(!session_id()) session_start();
    $oldSession = $_SESSION;


    $sessionFilePath = Mage::getBaseDir('session') . DS . 'sess_' . $_COOKIE['adminhtml'];
    $sessionContent  = file_get_contents($sessionFilePath);


    /** @var Mage_Admin_Model_Session $session */
    $session  = Mage::getSingleton('admin/session');
    $loggedIn = $session->isLoggedIn();

    //set old session back to current session
    $_SESSION = $oldSession;

    return $loggedIn;

if( isBackendUserLoggedIn() ){
    $logonStat = 'true';
} else {
    die('You must be logged on to access this page!');

1 Answer 1


You should use something like this instead of the session check you are doing based on a file.

//get the admin session
Mage::getSingleton('core/session', array('name'=>'adminhtml'));

//verify if the user is logged in to the backend
  //do stuff
  echo "go away bad boy";
  • It's not working for me Why ? Jul 10, 2017 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.