Magento1.9 Admin – Fix ‘Invalid Form Key. Please Refresh the Page’ Error

adminform-keymagento-1.9session

I regularly visit my site to make sure its working and noticed that images for products were not appearing, thinking it was a problem with indexing cache I tried to login to the admin panel and received the error:

"invalid form key. please refresh the page"

or

Other symptoms are customers could not add products to cart and extremely slow performance.

There are no errors in the logs (/var/logs)

What additional steps should I perform to resolve this issue?

Best Answer

It also happens if the cookie domain in System > Configuration > Web > Cookies is different from the actual site domain.

To remove the setting without access to the admin panel:

  1. use the following SQL query on the MySQL console or in a client like phpMyAdmin:

    DELETE FROM core_config_data WHERE path='web/cookie/cookie_domain';
    
  2. clear the cache. If you are using the default file based cache backend, delete all directories below var/cache.

Then as soon as you can log in again, set the correct cookie domain for each website or store (Example: .example.com for example.com, www.example.com and all other subdomains)

If you are using n98-magerun (and you should!), the same can be accomplished with:

n98-magerun config:delete web/cookie/cookie_domain
n98-magerun cache:clean config