cancel
Showing results for 
Search instead for 
Did you mean: 

'Invalid security or form key. Please refresh the page' on production server

'Invalid security or form key. Please refresh the page' on production server

When calling up the items for the page from the menu (new app), I get an error "Invalid security or form key. Please refresh the page. "

 

From the logs I find the following

 

“Request validation failed for action "Magento\Framework\App\Action\Forward\Interceptor" {"exception":"[object] (Magento\\Framework\\App\\Request\\InvalidRequestException(code: 0): Invalid request received at /var/www/html/magento/vendor/magento/module-backend/App/Request/BackendValidator.php:152)"} []”

 

This only on the production server, on the development server (XAMPP) everything works fine.

Who can help me on this issue?

I have already tried all the solutions proposed in the community for the issue “Invalid security or form key. Please refresh the page. "

 

Thanks

9 REPLIES 9

Re: 'Invalid security or form key. Please refresh the page' on production server

Hello @pietro_di loren ,

have you tried this,

 

Open your server's php.ini file with root user,

search for `max_input_vars` and set its value as `100000` 

 

max_input_vars = 100000

Thank you

Re: 'Invalid security or form key. Please refresh the page' on production server

Hi, @smita_kagwade ,

Thanks for the reply, but I've tried this solution before but it doesn't work.

 

Thanks!

Re: 'Invalid security or form key. Please refresh the page' on production server

@pietro_di loren,

 

kindly check this can be a full-page caching issue. and you can confirm that by disabling Full Page Cache for some time on the production server. 

if that works than kindly check the theme files on that page. 

 

Re: 'Invalid security or form key. Please refresh the page' on production server

Hi, @amitsamsukha 

I have already tried to clear all caches,

 

sudo chmod -R 0777 var/ pub/ generated/

sudo rm -rf var/cache/* pub/static/* generated/*

sudo php bin/magento setup:upgrade

sudo php bin/magento setup:di:compile

sudo php bin/magento setup:static-content:deploy -f

sudo php bin/magento indexer:reindex

sudo php bin/magento cache:flush

sudo chmod -R 0777 var/ pub/ generated/

 

but i always have the same problem

could the problem be related to the theme? how could i solve it?

on my xampp it works fine

Re: 'Invalid security or form key. Please refresh the page' on production server

@dilorenzopd73c try disabling your cache for some time on the production server 

sudo php bin/magento cache:disable 

 

Re: 'Invalid security or form key. Please refresh the page' on production server

@smita_kagwade @amitsamsukha I tried all the solutions mentioned above but none of them seems to be working. This is the follow up from the owner of the ticket created. Can anyone please look into this so that it will unblock us from our development?

Re: 'Invalid security or form key. Please refresh the page' on production server

@shivanisindd5a kindly share the URL where you are getting this issue 

Re: 'Invalid security or form key. Please refresh the page' on production server

@amitsamsukha  This is an internal link to the control panel and that the error is the one indicated in the first message  'Invalid security or form key. Please refresh the page`. I am facing this issue locally as well.

Re: 'Invalid security or form key. Please refresh the page' on production server

It's because you have validation with the form key. Check your action PHP file

If your request is for ajax use isajax=true in your call.

If not use the below function in your action PHP file

protected function isValidPostRequest()
{
$isPost = $this->getRequest()->isPost();
if(!$isPost) {
return true;
}
}


if your post the request you can also use it something similar to below to validate for key

protected function isValidPostRequest()
{
$formKeyIsValid = $this->_formKeyValidator->validate($this->getRequest());
$isPost = $this->getRequest()->isPost();
return ($formKeyIsValid && $isPost);
}

 

Don Udugala