1

The users of my Website told me that they got the tokenmismatchexception when the sent the formular.

If I try I didn't got it.

So, in which cases does the tokenmismatchexception come? How can I catch it?

Thank you in advanced.

Rob
  • 2,243
  • 4
  • 29
  • 40
Okay
  • 143
  • 2
  • 2
  • 10
  • 1
    Possible duplicate of [TokenMismatchException in VerifyCsrfToken.php Line 67](https://stackoverflow.com/questions/34866404/tokenmismatchexception-in-verifycsrftoken-php-line-67) – Zakaria Acharki Oct 20 '17 at 16:30
  • When session expires (user is logged out) you will get the `TokenMismatchException`. You can find settings for session in file `config/session.php` and the documentation [here](https://laravel.com/docs/5.5/session#configuration). – ljubadr Oct 20 '17 at 16:30
  • To test that out, you can change the line `lifetime' => 120,` to `lifetime' => 1,` in `config/session.php`. Wait 1 for minute and try to submit the form. – ljubadr Oct 20 '17 at 16:32
  • and don't forget to turn it back to 120 when you are done testing – ljubadr Oct 20 '17 at 16:33

1 Answers1

1

This error appears when:

  • The user leaves the page opened for a long time of period, The default time is 2 hours and can be configured in config/session - lifetime

  • When you submit a form without including the _token field or without excluding the url on app/Http/Middleware/VerifyCsrfToken

To put the _token field on any form you can use {!! csrf_field() !!}

You can check the docs for more information

Lloople
  • 1,827
  • 1
  • 17
  • 31