cancel
Showing results for 
Search instead for 
Did you mean: 

How to resolve 'Your session has expired' error when adding products to cart in Magento 2.4.2?

How to resolve 'Your session has expired' error when adding products to cart in Magento 2.4.2?

I am facing an issue in my Magento 2.4.2 installation. Every time I try to add products to the cart from the category page, I receive the error message "Your session has expired". However, I am able to add products to the cart without any issues from other parts of the store. I have tried to resolve the issue by following these steps:

 

php bin/magento setup:store-config:set --base-url="http://MYURL.com/" php bin/magento setup:store-config:set --base-url-secure="https://MYURL.com/"`

I cleared the Magento cache using the command:

 

php bin/magento cache:clean` php bin/magento cache:clean`

 

However, the issue persists and I am unable to add products to the cart from the product page.

Has anyone experienced a similar issue in Magento 2.4.2 and can provide any guidance or solution? Is there any other step I can take to resolve this problem?

I appreciate any help or suggestions you can provide. Thank you in advance!

 

1 REPLY 1

Re: How to resolve 'Your session has expired' error when adding products to cart in Magento 2.4.2?

Hello @rolymirand722e 

 

The "Your session has expired" error in Magento 2.4.2 typically occurs when the session timeout period is shorter than the time it takes to add products to the cart. To resolve this issue, you can try the following solutions:

  • Increase session timeout: You can increase the session timeout value in the Magento 2 configuration. Here's how:
    • Log in to the Magento 2 Admin Panel.
    • Navigate to Stores > Configuration.
    • Under Advanced, select Admin.
    • Expand the Security section.
    • Increase the value of the Admin Session Lifetime (seconds) field to a higher value.
    • Save the configuration and clear the cache.
  • Increasing the session timeout allows for a longer period before the session expires, giving you more time to add products to the cart without encountering the error.
  • Check server time settings: Ensure that the server time settings are correctly configured and synchronized. If the server time is out of sync, it can cause session-related issues. You may need to contact your hosting provider or server administrator to verify and adjust the server time settings if necessary.
  •  Verify cookie settings: Make sure that the cookie settings in Magento 2 are correctly configured. Incorrect cookie settings can lead to session expiration errors. To check and adjust the cookie settings:
    •  Go to Stores > Configuration in the Magento 2 Admin Panel.
    • Under General, select Web.
    • Expand the Default Cookie Settings section.
    • Ensure that the Cookie Lifetime value is set to a higher value or leave it as "0" to make it last until the browser is closed.
    • Save the configuration and clear the cache.
  • Adjusting the cookie lifetime can help maintain the session for a longer duration, reducing the occurrence of the session expiration error.
  • Check server PHP settings: Verify that the PHP settings on your server meet the requirements for Magento 2. Ensure that the session.gc_maxlifetime value in the php.ini file is set to a higher value than the session timeout set in Magento. You may need to consult with your hosting provider or server administrator to make any necessary adjustments to the PHP settings.

If you find our reply helpful, please give us kudos.

 

A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.

 

WebDesk Solution Support Team

Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789

Thank You,


WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789


Location: 150 King St. W. Toronto, ON M5H 1J9