Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 TokenMisMatchException on Production Server

I am encountering TokenMismatchException on my Production Server, but the application working fine on local Xampp server and another hosting. It our in house server, so we cannot changed it. We have to use it, but we did not understand where is the issue.

Please friends help me, did i need to change anything in server like plugin, extensions or anything else, Please let me know. Here is screen shot below:

Error on production when submitting login blank and geeting token mismatchexception

This on my personal hosting and the same is working fine here.

Above sceenshot is from Production and one of hosting provider. On production server laravel application giving tokenmismatchexception whereas same application working fine on another hosting provider. We did not understand why this is happening. Please suggest us what to do.

Update:

I have fresh laravel 5.2 and run php artisan make:auth after that i have given 777 permission to the folder, then donw nothing. Still i am getting this exception.

like image 697
Mandy Avatar asked Aug 01 '16 07:08

Mandy


3 Answers

Add this in your html form

 <input type="hidden" name="_token" id="_token" value="{{csrf_token()}}">

in blade

{!! Form::token() !!}

And add your route in web middwlware

Route::group(['middleware' => 'web'], function() {
      // Place all your web routes here...
});
like image 109
paranoid Avatar answered Nov 10 '22 19:11

paranoid


This is probably the sessions that are not being set properly. Try to delete your PHP_SESSID cookie or change the way the sessions are stored on the server.

You can also check if sessions are working properly with a testing route.

like image 2
corentingi Avatar answered Nov 10 '22 20:11

corentingi


I had this issue, for me the problem was

SESSION_DOMAIN=custom_domain_here

Setting in my .env file, which was different between production and local. This will cause the sessions to be created incorrectly for the domain and throw a TokenMismatch.

Hope this helps someone.

like image 2
Joel Avatar answered Nov 10 '22 20:11

Joel