Magento – Magento 1.9 can’t add items to shopping cart Form key problem

form-keymagento-1.9shopping-cart

I have several Magento stores hosted on bluehost. They had been running well for a couple of months and then suddenly one day the customers just could not add products to the shopping cart any more. The store just shows Shopping Cart is Empty.

After days digging into the code, finally I found out the problem caused by FORM_KEY. The form_key that server side fetches stays the same for one session, but the form_key on front side changes every time I refresh the page. So the form_key passed from front end form is different from the one server uses to validate.

The _validateFormKey() in addAction() function always returns false and the items cannot be added to shopping cart.

I tried to block caching by adding the following meta tags to each page, but it did not solve the problem.

meta http-equiv="Cache-Control" content="no-cache, no-store,
must-revalidate"

meta http-equiv="Pragma" content="no-cache"

meta http-equiv="Expires" content="0"

Any ideas?

Best Answer

Maybe you have some problem with cookies, please try to clear the value of web/cookie/cookie_domain and web/cookie/cookie_path, Make also sure that webserver user has right to write to session storage. checking session_save_path setting if you save session to files. It looks like this:

<session_save><![CDATA[files]]></session_save>
<session_save_path><![CDATA[/tmp/session]]></session_save_path>
Related Topic