Bobcares

Invalid form key. please refresh the page. magento 2 frontend: Fix

by | Sep 3, 2022

Let us examine the error invalid form key. please refresh the page. magento 2 frontend in depth. With the assistance of our Magento support services, we can you a detailed note on the error with the solutions.

Invalid Form key. Please Refresh The Page. Magento 2 Frontend

invalid form key. please refresh the page. magento 2 frontend

Despite its prevalence, this is not a specific Magento bug. It is one of the most commonly encountered Magento issues. The following are some of the Magento 2 shop actions that produce this error:

  • During the making of a configurable product with multiple attributes.
  • When adding a product to the wishlist.
  • While creating an account or signing, add to the cart on localhost.
  • When installing a new extension/ theme on Magento 2.
  • After upgrading Magento 2 version.

The reasons for Magento 2 “Invalid Form Key. Please refresh the page” error

Listed below are two of the most common or popular reasons for the error to get triggered.

1. PHP Max_input_vars value is not optimized for Magento 2

The date error is caused by an incorrectly specified Max input vars value in Magento 2. The server’s default PHP MAx input vars value is 1000, which is insufficient for Magento 2.

PHP Max input vars is the maximum amount of variables that the server can use for a single function in order to avoid overloading (this value is used mainly to protect the server from DDOS attacks).

2. Base URL on Localhost not recognized by Magento 2 system

If this problem occurs on Localhost, it is most likely due to utilizing Localhost as the website’s base URL rather than 127.0.0.1.

This will almost certainly result in a cookie system issue on Magento and a Magento 2 Invalid Form Key. If this is the case, please reload the website page.

Fix Magento 2 Invalid Form Key error. Please refresh the page

As noted in the content given above, there are two main causes of this problem. We’ll go over two corresponding solutions for them. Let’s get started on each solution straight away.

Solution 1: Increase max_input_vars in php.ini

Most of the time, we can resolve the Magento 2 error “Invalid Form Key.” Please refresh the page” by setting PHP Max input vars to the value required by Magento 2 to process its capabilities.

  • Set the Magento 2 Max input vars to 10000.
  • To change the value of PHP Max input vars, we must visit the server’s php.ini file.

To adjust PHP Max input vars, carefully follow the steps below.

  • When using a VPS/Dedicated server, log in via SSH with root access.
  • Enter the command: To locate the path to the php.ini folder, use php -i | grep ‘php.ini’. This will result in an output.
  • Set the Max input vars variable to 10000. Then, to save this folder, use the ESC key and type:wq.

    ; (e.g. by adding its signature to the Web server header).
    ; threat in any way, but it makes it possible to determine w
    ; on the server or not.
    expose_php = On
    ; Resource Limits ;
    max_execution_time = 30
    max_input_time = 60
    memory_limit = 128M
    max_input_vars = 5000;
    ; Maximum execution time of each
    ; Maximum amount of time each script
    ; Maximum amount of memory a script
    ; Error handling and logging ;
    ; error_reporting is a bit-field. Or each number up to get

  • Last but not least, restart your Apache. Now you can save a newly created product without facing any problems.

Solution 2: Change the base URL

Another reason for the invalid form key. Please reload the page. magneto 2 frontend error is the Magento 2 system does not recognize the base URL, which causes the frontend error. It usually occurs in a local setting (localhost). It is simple to resolve this issue; simply update the base URL to “127.0.0.1”.

php bin/magento setup:store-config:set --base-url="http://127.0.0.1:8080/"

We can also go to PHPAdmin and search for the table core config data, then change the value of web/unsecure/base url to 127.0.0.1. We can modify the base-url-secure: to HTTPS if we install Magento 2 on HTTPS.

php bin/magento setup:store-config:set --base-url-secure="https://127.0.0.1:8080/"

Finally, once we’ve changed the base URL, we should flush the cache to save the changes by running the following command:

php bin/magento cache:flush

And then run the following command to clear the Magento 2 cache folder:

sudo rm -rf var/cache var/generation var/page_cache

Solution 3. Update Magento or improve Magento speed so all Javascripts are loaded fast enough.

Consider the following scenario: “The Form Key is invalid. Please reload the page “. Ask a developer to look into a Magento 2 frontend error that arises on a storefront in the latest version of Magento.

They must modify the Add to Cart button template so that it appears only after all JS scripts have been loaded. Finally, please refresh the website to see whether the error has been resolved.

[Need assistance with similar queries? We are here to help]

Conclusion

To conclude the error invalid form key. please refresh the page. magento 2 frontend can be triggered by two main factors. We can effectively manage the error by analyzing the error-causing issues with the assistance of our Magento support services.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF