4

I'm using Magento ver. 2.4.3-p1

I get the following exception in the admin panel when staying away for a long time.

TypeError: strtotime() expects parameter 1 to be string, null given in /var/www/html/vendor/magento/module-security/Model/AdminSessionInfo.php:136
Stack trace:
#0 /var/www/html/vendor/magento/module-security/Model/AdminSessionInfo.php(136): strtotime()
#1 /var/www/html/vendor/magento/module-security/Model/AdminSessionInfo.php(119): Magento\Security\Model\AdminSessionInfo->isSessionExpired()
#2 /var/www/html/vendor/magento/module-security/Model/AdminSessionInfo.php(108): Magento\Security\Model\AdminSessionInfo->checkActivity()
#3 /var/www/html/vendor/magento/module-security/Model/Plugin/AuthSession.php(74): Magento\Security\Model\AdminSessionInfo->isLoggedInStatus()
#4 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Security\Model\Plugin\AuthSession->aroundProlong()
#5 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Backend\Model\Auth\Session\Interceptor->Magento\Framework\Interception\{closure}()
#6 /var/www/html/generated/code/Magento/Backend/Model/Auth/Session/Interceptor.php(50): Magento\Backend\Model\Auth\Session\Interceptor->___callPlugins()
#7 /var/www/html/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(127): Magento\Backend\Model\Auth\Session\Interceptor->prolong()
#8 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch()
#9 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Catalog\Controller\Adminhtml\Product\Attribute\Index\Interceptor->Magento\Framework\Interception\{closure}()
#10 /var/www/html/generated/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Index/Interceptor.php(32): Magento\Catalog\Controller\Adminhtml\Product\Attribute\Index\Interceptor->___callPlugins()
#11 /var/www/html/vendor/magento/framework/App/FrontController.php(245): Magento\Catalog\Controller\Adminhtml\Product\Attribute\Index\Interceptor->dispatch()
#12 /var/www/html/vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse()
#13 /var/www/html/vendor/magento/framework/App/FrontController.php(147): Magento\Framework\App\FrontController->processRequest()
#14 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch()
#15 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent()
#16 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#17 /var/www/html/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins()
#18 /var/www/html/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch()
#19 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Http->launch()
#20 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\Http\Interceptor->___callParent()
#21 /var/www/html/vendor/justbetter/magento2-sentry/Plugin/GlobalExceptionCatcher.php(58): Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}()
#22 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(135): JustBetter\Sentry\Plugin\GlobalExceptionCatcher->aroundLaunch()
#23 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\Http\Interceptor->Magento\Framework\Interception\{closure}()
#24 /var/www/html/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http\Interceptor->___callPlugins()
#25 /var/www/html/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
#26 /var/www/html/pub/index.php(29): Magento\Framework\App\Bootstrap->run()
#27 {main}

I'm using the developer mode and I fix it temporarily by clearing the cookies, but is there another way to fix it permanently?

6 Answers 6

6

In Firefox, clearing the cache and site data worked for me.

2
  • But that's just a workaround... Error will come again Commented Nov 26, 2022 at 15:50
  • I can confirm that using incognito tab worked when I had this error.
    – TheFrakes
    Commented Feb 13 at 14:13
2

issue in vendor/magento/module-security/Model/AdminSessionInfo.php you need to replace this

public function isSessionExpired()
{
    $lifetime = $this->securityConfig->getAdminSessionLifetime();
    $currentTime = $this->dateTime->gmtTimestamp();
    $lastUpdatedTime = $this->getUpdatedAt();
    if (!is_numeric($lastUpdatedTime)) {
        $lastUpdatedTime = strtotime($lastUpdatedTime);
    }

    return $lastUpdatedTime <= ($currentTime - $lifetime) ? true : false;
}

with

public function isSessionExpired()
{
    $lifetime = $this->securityConfig->getAdminSessionLifetime();
    $currentTime = $this->dateTime->gmtTimestamp();
    $lastUpdatedTime = $this->getUpdatedAt();
    if (!is_numeric($lastUpdatedTime)) {
        $lastUpdatedTime = $lastUpdatedTime === null ? 0 : strtotime($lastUpdatedTime);
    }

    return $lastUpdatedTime <= ($currentTime - $lifetime);
}
2
  • So do you expect that is an issue that needs to be reported to Magento?
    – AboElnouR
    Commented Jun 9, 2022 at 14:34
  • 2
    This doesn't seem to fix it. This invalidates all sessions so no login session will work
    – Zudian
    Commented Jun 21, 2022 at 9:25
1

If you have this error & you are using Adobe Commerce version there is an available quality patch to fix this

https://support.magento.com/hc/en-us/articles/4849817606157-MDVA-42269-Admin-user-cannot-log-into-Admin-due-to-the-TypeError-error

0

Suggested Fix:

Return true if the session is blank: https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Security/Model/AdminSessionInfo.php#L130

public function isSessionExpired()
{
    $lifetime = $this->securityConfig->getAdminSessionLifetime();
    $currentTime = $this->dateTime->gmtTimestamp();
    $lastUpdatedTime = $this->getUpdatedAt();
    if (empty($lastUpdatedTime)) {
        return true;
    }
    if (!is_numeric($lastUpdatedTime)) {
        $lastUpdatedTime = strtotime($lastUpdatedTime);
    }

    return $lastUpdatedTime <= ($currentTime - $lifetime) ? true : false;
}

thanks to https://github.com/pmzandbergen:

https://github.com/magento/magento2/issues/34531#issue-1044583011

1
  • Can you please share why do we need to change the core code?
    – Asrar
    Commented Feb 2, 2023 at 2:13
0

I had the same issue on Adobe Commerce v2.4.4. A safe way is to set the lowest value for admin/security/session_lifetime to 60. Then, after 60 seconds, clear redis, if used, and application cache.

No need to touch core code!

1
  • Then what? Will it solve the issue permanently, or will it only pass the situation?
    – AboElnouR
    Commented Feb 2, 2023 at 7:14
0

Changing the source code may only suppress this error. The problem is that the session works not correctly. For me helps the setting of the max_session_size_admin with the command

php bin/magento config:set system/security/max_session_size_admin 1024000

Your Answer

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

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