How to fix “Invalid Form Key. Please refresh the page.” error on Magento Backend

So you’re also having this “Invalid Form Key. Please refresh the page.” error and not able to login to your newly installed Magento Backend interface? No worries in this short article we will learn how to fix it.
There are number of reasons behind this and different solution works for different people so lets closely go through some of them.
Solution # 1: Use Database to save session
Often it seems that the “files” method to store session doesn’t work due to file permissions or other related issues so you can switch to Database method by making the change in app/etc/local.xml
Search for:
< ![CDATA[files]]>
and replace with:
< ![CDATA[db]]>
Save the file and sessions will now be stored in the database instead of files. Although you might see performance issues if you are running a large web store or multi sites with great number of products.
Solution # 2: Files & Folders Permission
So instead of switching to Database method for storing sessions we discussed above you make sure the folder /var/cache have the right permissions (0755 should be enough though but it has been noticed that some servers require 0777 on those folders), and writable to the user running php so magento can create new session files in that folder. if folder is not writable you are more likely to encounter the error.
Solution # 3: Core Config Data Table
For many users the problem lies in database. There are 2 of the possible fixes written below, if this is really a database issue.
Please note: If you find multiple entries for the following be sure to only use the default one or the one you want to change because resetting/removing the wrong entry might break your magento webstore completely.
- Reset the following:
Browse core_config_data table (you might have to add the db/table prefix)
SELECT * FROM `core_config_data` WHERE `path` = "web/cookie/cookie_domain"; Set the above path value to null SELECT * FROM core_config_data WHERE path="web/cookie/cookie_path";
set the value to above path to /
- Delete the following entries
If the above code not help you then deleting the following entries from core_config_data table will help fixing the issue.
DELETE FROM `core_config_data` WHERE `path` = "web/cookie/cookie_domain"; DELETE FROM `core_config_data` WHERE `path` = "web/cookie/cookie_path";
Solution # 4: Cookies, Cache issue
If nothing mentioned above works for you don’t give up it’s more likely a bad Cookie issue. The simple solution is to delete cache, cookies from your browser. Also its nice to clear up magento cache if it doesn’t hurt you.
Please feel to reach to us if you don’t get it fixed.