Sometimes I'm receiving this message below during the customer login after being changed the cookie domain through the admin panel.

Do you know why and when this message shows up?

Invalid Form Key. Please refresh the page

Magento2 Invalid Form Key. Please refresh the page

3 Answers 3


Magento 2 - What is the use of formkey

If you receive the error message, in cases where the form_key should still be valid, it is in most cases an issue in the cookie setup. If Magento can not find the form_key from your cookie, the form_key validation will fail. Issues for this could be an invalid cookie-domain, cookie-lifetime, ...


I solved it not just refreshing the caches invalidated but flushing all the caches possibles via admin panel through these 3 sections in the image below.

Do it mainly if you are using compiled configurations.

Magento 2 cache flush cookie domain issue

Make sure that you are using the right cookie domain configured.


After copying your magento 1 site to a new domain, Varien.php may still have the old domain name in the file.

To ensure your admin form is using the new 'cookie domain, update any references to your old domain in the Varien.php file located in your site at: /<magento_html_dir>/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php

After making the edits, run a cache flush/clean, and reindex all (n98-magerun tool is good for this): Example: n98-magerun tool n98-magerun cache:clean n98-magerun cache:flush n98-magerun index:reindex:all

Hope it works!

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.