magento-2.3

Your session has been expired when item added to cart at cart page in magento2


When I was trying to add products on cart in magento2, but it showing an error. :(

Your session has expired


Solution

  • This error is occurs when form key is not valid.

    if (!$this->_formKeyValidator->validate($this->getRequest())) {
                $this->messageManager->addErrorMessage(
                    __('Your session has expired')
                );
                return $this->resultRedirectFactory->create()->setPath('*/*/');
            } 
    

    You should check form key is exist or not in Add to cart request. problem is due to this form key.

    Also try these solutions as well

    Yes, use 127.0.0.1 instead of localhost

    UPDATE `core_config_data` SET `value` = 'http://127.0.0.1/magento/' WHERE `core_config_data`.`path` = 'web/unsecure/base_url';
    UPDATE `core_config_data` SET `value` = 'http://127.0.0.1/magento/' WHERE `core_config_data`.`path` = 'web/secure/base_url';
    

    I hope it will helpful for you.