Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSRF token doesn't work (yii2) with https

Tags:

yii2

I test app on local is ok. I deploy to server with https domain. When i submit form then show 400 Error: Bad Request (#400): Unable to verify your data submission.

And have problem with Https, how can i fix it

like image 709
dungphanxuan Avatar asked Aug 30 '25 18:08

dungphanxuan


1 Answers

Maybe you have got non-secure cookies blocked when sending over https. Try this in configuration:

return [
    // ...
    'components' => [
        // ...
        'request' => [
            'class' => 'yii\web\Request',
            'csrfCookie' => [
                'httpOnly' => true,
                'secure' => true,
            ],
        ],
    ],
];
like image 193
Bizley Avatar answered Sep 02 '25 16:09

Bizley