I am unable to save the product in Magento 2.

It shows "Invalid Form Key. Please refresh the page. in local

enter image description here

how to resolve this?

  • 2
    Please check your cookie setting – Amit Bera Feb 20 '17 at 14:56

This bug arises due to php.ini variable "max_input_vars" Increase it to 10000 through below php function:

ini_set('max_input_vars', 10000);

OR Using linux command line

cd /etc/php/7.0/apache2/
vi php.ini (Open for edit and set max_input_vars=10000)
:wq(Press esc and write the mentioned command to save and exit)
sudo /etc/init.d/apache2 restart(Restart Server)
  • Thanks for you replay @ahmad vaqas khan let me check and update you thanks... – NIPPU Apr 21 '17 at 8:29
  • ok. keep updated regarding it. – Ahmad Vaqas Khan Apr 21 '17 at 10:48
  • It worked for me. Very interesting though. How did you debug that? – Abhishek Jakhotiya Aug 7 '17 at 13:53
  • @AbhishekJakhotiya : Great . I googled and came across this useful info . Often being PHP Core deveoper is quite helpful along with Magento developer . – Ahmad Vaqas Khan Aug 7 '17 at 17:59
  • I have changed max_input_vars to 10000, but still having same issue. I am working on local (using ubuntu 16.04) and magento 2.3 – Hemant Kumar Dec 21 '18 at 5:51

If you are running this Magento site on a local machine (local host) as your question seems to indicate, you may have trouble using the: http://localhost/ syntax, as Magento 2 doesn't fully know how to deal with cookie.

Instead, I'd recommend using to access the local site; in this case your browser should be able to recognize this more easily and work with Magento's cookies properly.

You may need to set a cookie domain in the admin area of Magento.

I hope this helps...


Have you tried using different browser? I usually use Google Chrome but came across this problem, setting max_input_vars to higher values didn't help, neither using local IP address instead of localhost, but I tried using Firefox and it worked.

  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review – Murtuza Zabuawala Jan 7 at 8:13
  • I guess it denepnds on the wording then. "using firefox instead of google chrome solved my issue." could be the right variant of my answer like a previous one right? I wanted to express myself in more detailed way and telling I've tried previous answers and they didn't work for me - it's not just a hunch. It is a possible solution (like the other answer that didn't work for me - they could work for some others though). – Máté Dusik Jan 8 at 9:15

Try This Ubuntu 14.0.4 System in magento 2.3-invalid Form key error.

I face invalid Form key error on frondend-side insertion, But crome browser only occured this error, Insertion correctly run in firefox browser.

I solved this error Following steps:-

Change your base URL from localhost to

Using localhost as the domain in your base URL causes problems in Magento 2.

Magento's base URL configuration is located in the core_config_data table. The following values may need to be changed:

web/unsecure/base_url web/secure/base_url For example, if you previously had http://localhost/magento2community/, you should change it to

After changing the url, flush the cache (bin/magento cache:flush). You might also need to clear out your var directories.

I find this solution through this Like https://magento.stackexchange.com/a/122167/78151


setting max_input_vars to 10000 in php.ini resolved my issue.


In my case it was due to the website protection settings of Firefox.

Firefox blocked some cookies that were needed by Magento2.

So I had to disable it by going to Preferences -> Privacy & Security -> Browser Privacy and choose "Custom" and uncheck the "Cookies" option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.