[FIXED]: Magento 2 Invalid Form Key. Please Refresh the Page

[FIXED]: Magento 2 Invalid Form Key. Please Refresh the Page

No doubt that Magento is a robust and feature-rich eCommerce platform. However, like any other platform, you can encounter issues. While they are frustrating, you can easily resolve them with just a few clicks and tweaks. Speaking of errors, one error you may encounter is “invalid form key. please refresh the page. Magento 2”. The frustrating part is not the error but the fact that refreshing the page does little to fix it. Rather than engage a specialist to resolve this issue, just follow our instructions.

When Does this Error Appear?

magento-2-invalid-form-key

You may encounter this error at various stages, including:

Cause Of the Error

This error “Invalid Form Key. Please Refresh the Page” occurs in Magento 2 because of the limited number of variables that can be used for a single function. The max_input_vars in the php.ini file is the directive that holds this value. By default, the value of max_input_vars is set to 1000.

Fixing the “Magento 2 Invalid Form Key. Please Refresh the Page” Error

To get rid of the issue "Invalid Form Key. Please Refresh the Page", you should raise the value of max_input_vars to something between 5000 to 10000. To do this, you need to edit the php.ini file.

Here is how you can do this.

  • Log in to your website server using SSH
  • Open php.ini file and increase the value of max_input_vars to let’s say 7000.
Note: The path of the php.ini file can be found with this command.
php -i | grep php.ini	
  • Save the php.ini file and then restart your webserver.
To restart the apache web server, use the following command.
	sudo /etc/init.d/apache2

This will resolve the issue in all Magento versions (2.1, 2.2, 2.3, 2.4)

Conclusion

If you face any issue while fixing this error, then feel free to contact our support team for a quick fix.

Related Articles: