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

[FIXED]: Magento 2 Invalid Form Key. Please Refresh the Page
You may end up with this error when you try to save a product with too many custom options or attributes.

Cause of 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.

Solution:

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)

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

Related Articles: