1

Csrf token automatically regenerate on each request in Laravel which cause csrf token mismatch on production server. On local server it is working fine I also print both token on verifiedCSRFToken.php file on product server

 $token = $this->getTokenFromRequest($request);
             echo $request->session()->token();
             echo "====";
             echo $token;
             die('Hi');

$token remain same but $request->session()->token() always changing on product server

3 Answers3

4

_________(space before php tag in your routing file or any other file of laravel will cause unexpected issue on laravel )

0

I had this same problem and what i did was:

First in your .env file remove:set session driver like: SESSION_DRIVER=file (if your want it to save to a file)

then do: php artisan cache:clear then php artisan config:clear

that worked for me.

and forget to checkout application mode from .env

0

If you are sending many ajax requests within one page, I may suggest you use the token this way <meta name="csrf-token" content="{!! csrf_token() !!}">. And get it with '_token': $('meta[name="csrf-token"]').attr('content'),

  • Dear issue is something else everything working on local server on local server cookies are generated by laravel but on production server it is not generating cookies. That is the reason it is showing csrf token mismatch. due to this laravel generating new csrf token everytime in session. – Vishal Dhiman Jan 02 '20 at 13:28