I have added this code Mage::register('test_checking_login', 1); after admin login and when expire session or delete session directory from var/ folder so Mage::registry('test_checking_login') displays null value why it does not display set value.How can I achieve this ?


4 Answers 4


I think you are confusing 2 concepts.
Session and Registry.

Session values are carried over from request to request until the session expires or until you remove them.

Registry values are some kind of global values but all in the same request.
As soon as the request is over your registry values are not available anymore.

I think you need

Mage::getSingleton('adminhtml/session')->setData('test_checking_login', 1)  
  • Ok Let me try this code Dec 27, 2016 at 10:38
  • Not work I am not getting Value 1 by this code Mage::getSingleton('adminhtml/session')->getData('test_checking_login') after logout admin Dec 27, 2016 at 11:10
  • If I set value in admin session variable after login and I want to get that admin session variable value after admin logout Dec 27, 2016 at 11:15
  • I don't think that works when you logout, the session is destroyed.
    – Marius
    Dec 27, 2016 at 11:17
  • therefore I was using mage registry so in this situation how can I achieve this functionality ? Dec 27, 2016 at 11:19

I'm not fully aware of your use case as your question is quite narrow but here's a shot.

From your comments on other answers you need this data to

  • Persist after sessions are cleared (eg after logout)
  • Persist Between separate requests
  • And as you previously tried using the session, I assume this data is on a per-admin-user basis.

This really means it needs to be persistent storage (database) and linked to the current admin user.

There is a database field on the admin_user table called extra that I think you may be able to utilise. I don't think it's actually used anywhere in core magento, but you may want to watch out in case any of your extensions are using it.

Saving your data

$user = Mage::getSingleton('admin/session')->getUser();
if ($user instanceof Mage_Admin_Model_User && $user->getId()) {
    $extraData = $user->getExtra();
    if (!is_array($extraData)) {
        $extraData = array();
    $extraData['test_checking_login'] = 1;

Loading your data

$testCheckingLoginValue = 0;

$user = Mage::getSingleton('admin/session')->getUser();
if ($user instanceof Mage_Admin_Model_User && $user->getId()) {
    $extraData = $user->getExtra();
    if (is_array($extraData) && isset($extraData['test_checking_login']) {
        $testCheckingLoginValue = $extraData['test_checking_login']

return $testCheckingLoginValue

Tech references

  • Roadgers I have created a different login page with custom module and create admin controller for other role user like sales manager so I do not want to permission to other role user to access admin login page so When Sales Manager login by custom admin login page it logged in correctly and its display limited resources but when session expires it redirects admin original login page.so I want to redirect to custom login page to other role user .So please advice me on this stuff. Dec 29, 2016 at 13:39
  • If I set value after login in user table,if seller login in desktop and after few min it try to login by mobile so what happen ? because in this situation test login value entered 1 in table Jan 2, 2017 at 10:38

In Admin:

To save data

$value='my value';
Mage::getSingleton('adminhtml/session')->setData('name', $value);

To get it


In Frontend:

To save data

$value='my value';
Mage::getSingleton('core/session')->setData('name', $value);

To get it


I have not tested the following but give it a go:

  1. Using your custom login admin controller, set cookie when custom user role logs into system except admin role such as: Mage::getModel(‘core/cookie’)->set($name, $value);
  2. Now, override adminhtml_controller_action_predispatch_start [I referred Admin/Controller/Action.php file to find out this event] method and set condition such as:

         //Do process
  3. Delete cookie when custom user role logs out from system.

In this way, say for e.g. if session gets expired but cookie has been set, it will be checked using that event specific method. In case if admin logs in then we do not need to set cookie [that can be achieved by checking user role when loginAction gets called].

As I mentioned, I have not tested this approach, may be anyone else can suggest better approach. I hope this makes sense.

  • I tested but it does not work because whole cookie expire after logout even if I set custom value in cookie Jan 2, 2017 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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