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,
<?php
require $_SERVER['DOCUMENT_ROOT'] . "/app/Mage.php";
function isBackendUserLoggedIn() {
 if (!array_key_exists('adminhtml', $_COOKIE)) return false;
 if(!session_id()) session_start();
 $oldSession = $_SESSION;
 Mage::app();
 $sessionFilePath = Mage::getBaseDir('session') . DS . 'sess_' . $_COOKIE['adminhtml'];
 $sessionContent = file_get_contents($sessionFilePath);
 session_decode($sessionContent);
 /** @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
if(Mage::getSingleton('admin/session')->isLoggedIn()){
 //do stuff
}
else
{
 echo "go away bad boy";
}
 
 answered Jul 13, 2015 at 18:05
 
 
 
 mbalparda 
 
 7,4033 gold badges24 silver badges46 bronze badges
 
 - 
 It's not working for me Why ?Amaresh Tiwari– Amaresh Tiwari2017年07月10日 06:44:20 +00:00Commented Jul 10, 2017 at 6:44
 
default