"invalid form key. please refresh the page" - cannot login to admin panel

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

I am posting the question / answer because I couldn't find anything relevant.

The issue was that the drive on which my magento installation resides was full. I freed up some room, clear the /var/session and /var/cache and everything went back to normal.


There are 3 solutions:

  1. Use these commands in phpmyadmin

    DELETE FROM core_config_data WHERE path='web/cookie/cookie_domain';

    DELETE FROM core_config_data WHERE path='web/cookie/cookie_path';

Now Try to login.

2.Delete everything in var folder and then check if it works.

3.Replace the .htaccess file with sample .htaccess file and then try to login the admin.

Hope it help you.