TokenMismatchException in line VerifyCsrfToken.php 67 only on the real server

I get this error when I try to use authentication in Laravel 5.2. This happened after switching to a live server. On my local server everything is working fine.

The token inside the form and Session: token () are the same.

UPD: I put dd ($ request) in laravel / framework / src / Illuminate / Foundation / Http / Middleware / VerifyCsrfToken.php

and the value of _token does NOT match the input of _token on the form.

I did my best:

  • Disable CSRF for authentication routes, add routes to the array, except for the array in Midd / VerifyCsrfToken.php.
    • Set 777 permissions on the / storage / bootstrap folders.
    • Used {!! csrf_field () !!} and name = "_ token" value = "{{csrf_token ()}}" ">.
    • Changed domain in config / session.php.
    • Php artisan key: generate.
    • Reinstalled Auth. Also routes where I have middleware = auth.basic. I get "Invalid credentials" without even asking first about login.

On my local server everything is working fine.

+7
php laravel-5
source share
2 answers

What does your handler look like?

<?php ... public function handle( $request, Closure $next ) { if ( $this->isReading($request) || //$this->runningUnitTests() || $this->shouldPassThrough($request) || $this->tokensMatch($request) ) { return $this->addCookieToResponse($request, $next($request)); } // redirect the user back to the last page and show error return Redirect::back()->withErrors('Sorry, we could not verify your request. Please try again. (You waited too long to submit your form)'); } 
0
source share

Try it, it will solve your problem, this is due to the conflict of http and https.

Go to the file "session.php" change this:

 'secure' => env('SESSION_SECURE_COOKIE', false), 

to that:

 'secure' => true, 
0
source share

All Articles