How to Fix Admin Session Magento Error Strtotime Excepts Parameter

In the latest Magento releases, many developers have reported trouble with upgradation. Their main pain point is the Strtotime error which restricts them from logging into the admin. So how do you get rid of this error? Let’s delve deeper into the likely causes behind the Admin errors and the solutions developers should use to overcome them. Table of Contents

What is Magento Strtotime Error?

The Magento Strtotime error expects parameter 1 to be a string exception error in the admin panel that generally occurs due to the session storage during a Magento version upgradation. This restricts Admin users from logging into the Admin due to TypeError. You can fix this error by applying the Magento Security Patch of MDVA-42269 but you may have to troubleshoot many reasons for the error. Let’s check out the possible reasons behind the Strtotime error.

Why Does Strtotime Error Occur?

The Magento Strttotime error can occur for a number of causes, including: Session storage is empty: Magento 2 admin session timeout is set to 900 seconds by default. Whenever any module or patch is installed, the session time is expired, resulting in a Strtotime error. Upgrading Magento Store: The function accepting the Admin user session gets null during the upgradation.

How to Fix the Magento Strtotime Error

Some of the possible fixes for Magento Strtotime error include the following:

Apply the Security Patch

Magento 2 contains complex code and structure, but when it comes to error and maintaining code quality standards, Adobe Commerce delivers individual patches that contain the fixes for the installed version of Magento. The best way to fix this error is applying the security/quality patch that Adobe Commerce releases, i.e., MDVA-42269. Please note that the above patch is compatible with Adobe Commerce versions (all deployment methods), including 2.4.3-p1 – 2.4.3-p2, 2.3.7-p3, and Magento open source >=2.4.3-p1 <2.4.5.

Clear Cache

Magento 2 has a strong cache management system that saves a lot of data for better performance. Sometimes the error is resolved by merely flushing the cache. It is recommended to flush the cache during the development process, like installing or updating the module. You may run the command below to clean the cache via command line:
php bin/magento cache:clean

php bin/magento cache:flush
Note: Clear your browser’s cookies and refresh the page to check if the error is resolved.

Fix the Code (Put Any other Suggestions)

You can also fix your code to get rid of the Strtotime error. Make the below-mentioned changes: Open the file: vendor/magento/module-security/Model/AdminSessionInfo.php
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;

}
Replace with code to Return True if Session is Blank:
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;

}

Additional Tip For Magento 2.4.4

Users running Magento version 2.4.4 can fix the Strtotime error by running commands as well. Follow the steps below:
  • First, truncate the database table:
TRUNCATE admin_user_session;
  • Run the following command:
php bin/magento config:store:get system/security/max_session_size_admin 868000
  • Increase the time as per your need.

Final Words

Magento TypeError: strtotime() expects parameter 1 to be string, null given error insidcated your current session has expired. However, it can be resolved by following the proper guidelines and practices shared in this blog. If the error still persists after trying out the solutions shared above, we recommend contacting your hosting provider.
Jyotishna Kumari

Jyotishina is the Magento Community Expert at Magenticians and has 4 years of experience in web development. She has worked on e-commerce sites with custom development of modules on Magento 1 and 2. She loves to travel and explore new ideas whenever she finds time.

Share
Published by
Jyotishna Kumari

Recent Posts

Building Employee Trust and Dedication – A Complete Guide

In the highly competitive modern workplace, trust, and employee loyalty are crucial factors for long-term… Read More

3 months ago

12 Winning Strategies for Small Businesses Marketing

In the ever-evolving world of small business developing and implementing effective marketing strategies is critical to… Read More

3 months ago

Top 10 App Development Companies in Dubai 2024

With one of the highest internet penetration rates, the UAE has set out to revolutionize… Read More

3 months ago

Transforming Industries: How Amazons GPT44X is Revolutionizing AI Technology

Artificial Intelligence (AI) has been continually evolving, leading to remarkable advancements in various industries. Among… Read More

8 months ago

Top Magento 2 Extensions for 2023

Extensions, extensions and lots of extensions. We all love extensions, don’t we? After all, extensions… Read More

11 months ago

Unleashing the Power of Software Testing: Cooperating with a Testing Firm

Software quality is crucial to a firm's success across industries in the quickly changing digital… Read More

11 months ago