Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sportyboy's avatar

TokenMismatchException in VerifyCsrfToken.php line 67 in Laravel 5.2

I'm working on a laravel 5.1 project that requires login after upgrading to laravel 5.2 error of TokenMismatchException in VerifyCsrfToken.php line 67 came up each time I try to use form in my application. how can I fix this issue. I use html facade. I'm hoping to hear from you guys @Snapey

0 likes
23 replies
dawiyo's avatar

Are you sure your CSRF token is being outputted in the HTML source?

1 like
HomiWong's avatar

update your post and bring your code ....

1 like
thomaskim's avatar

99% of the time, this is because people aren't putting their routes inside the web middleware group. Since you did not mention that at all, I'm going to guess that that is your problem.

https://laravel.com/docs/5.2/routing#basic-routing

By default, the routes.php file contains a single route as well as a route group that applies the web middleware group to all routes it contains. This middleware group provides session state and CSRF protection to routes.

Any routes not placed within the web middleware group will not have access to sessions and CSRF protection, so make sure any routes that need these features are placed within the group. Typically, you will place most of your routes within this group:

Route::group(['middleware' => ['web']], function () {
    // Put all your routes inside here.
});
jekinney's avatar

If it's out side the web middleware it won't even check the token.

salone's avatar

what kind of session driver do i need to set to solute this situation?

Regards,

sportyboy's avatar

All my routes are in the Route::group(['middleware' => ['web']], function () { // Put all your routes inside here. });

I don't know how to fix it.

sportyboy's avatar

My Kernel.php file looks exactly like the content in the link

Terumi's avatar

Same problem here... Any solution? All the things that had to be checked, were checked (route middleware, new kernel, csrf_token on view) but the problem persists.

Lerouse's avatar

I had the same issue, I have just spent an hour wondering what had happened seems that enctype="text/plain" was the issue (still have no idea how that got added in there).

Hopefully this will help someone else.

Terumi's avatar

What did the trick for me was to set the session host to localhost in the config/session.php file.

1 like
kernel's avatar

i had the same issue , the solution is simple for me i just need to create a key for my application with :

php artisan key:generate

1 like
cdiazr's avatar

I got exactly the same issue but mine is even interesting! just it happens on the remote server, production, not in local server.

daniel1975's avatar

Hi cdiarz, Do you find solution for this problem?

pgichure's avatar

I got the same issue as cdiazr has. Works well on local server but the issue occurs on remote server

manel_ds's avatar

I got the same issue. In local server works fine, but in a remote web server fails.

I checked all points that are mentioned in comments of this thread but doesn't works.

If I disable the csrf validation, then auth no save the session. This make me thinks that my problem is in the sessions. If I debug the function that compares the tokens, I see that two different tokens arrive to the method.

I use laravel 5.3 with the file driver for sessions, the folders have good permissions, if I remove all files in the session folder, new files are created.

I found some threads with the same issue:

https://github.com/laravel/framework/issues/16064 https://github.com/laravel/framework/issues/15040 https://laracasts.com/discuss/channels/laravel/53-tokenmismatchexception-in-laravels-auth-form

Did you find any solution?

manel_ds's avatar

Update:

I downgrade my project to Laravel 5.0 and the problem persist. In my localhost and other servers it works. I contact with the hosting in order to check all parameters that may cause this problem.

cdiazr's avatar

@daniel1975 yes I found the issue. It was the secure configuration for session.php

It was set up as "false" and I got an SSL working on my hosting, so I had to set it up as "true" on the remote server.

raiomido's avatar

Do not edit your Laravel files. It is usually the last thing with the problem. It is most likely a permission issue. If developing on Linux this happens because, www-data is being denied permission to write to storage directory. To fix this, just run

cd /pathtorootdirectory
$ sudo chown -R www-data:www-data storage

Please or to participate in this conversation.