VerifyCsrfToken.php第68行中的TokenMismatchException:Laravel 5.3

I have been looking for answers around the net for 3 hours now, and have tried so many solutions but it did not work. I have tried: answers from here

But none of them worked

Solution 1:

sudo rm -rf storage/framework/sessions/*
sudo php artisan cache:clear

Solution 2:

Clearing my cache and cookies in my browser, then running

php artisan config:cache and php artisan cache:clear

Solution no. 3

enter image description here

Solution no. 4

enter image description here

Solution no.5

I tried changing my {{ csrf_field() }} to {!! csrf_field() !!}

Solution no. 6

I tried moving Auth::routes(); on top of my web routes.

Solution no. 7

enter image description here

Solution no. 8

I have changed my code from:

 <form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
   {{ csrf_field() }}

to:

 <div class="panel-body">
    {!! Form::open([ 'route' => 'login', 
                     'method' => 'POST' ]) !!}

I even tried adding a {{ csrf_field() }} in Form::open

I even tried adding another bracket {{{ csrf_field() }}}

Solution no. 9

Desperately restarting my server(MAMP) then clearing cache

There is another solution, which says that I should download a fresh install of Laravel, but I cannot do that because this is a big project.


Here is my .env file

API_DEBUG=true
APP_ENV=local
APP_KEY=base64:g43UiAlu11L/y9ThUjiVqFi52/d2Jf/JHaPNwkwzU4o=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://127.0.0.1

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

SESSION_SECURE_COOKIE=true

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=

API_PREFIX=api
API_SUBTYPE=app
API_VERSION=v1

JWT_TTL=20160

SIGN_UP_RELEASE_TOKEN=false
PASSWORD_RESET_RELEASE_TOKEN=false

PAGINATION_ITEMS_PER_PAGE=10

# Database Connections

DB_CONNECTION=mysql-core
DB_CORE_HOST=localhost:8889
DB_CORE_PORT=3306
DB_CORE_DATABASE=core
DB_CORE_USERNAME=root
DB_CORE_PASSWORD=root

my Kernel.php

class Kernel extends HttpKernel
{
protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
];

/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'secure.requests',
    ],

in my session.php

'driver' => env('SESSION_DRIVER', 'file'),
'files' => storage_path('framework/sessions'),
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),

Here's my web.php

<?php

Route::group([ 'middleware'  => [ 'secure.requests' ] ], function() {

    Auth::routes();

    Route::get('/', function () {
        return view('welcome');
    });

});

I am also using the laravel dubugbar enter image description here

It's a long post, but I am desperate to be able to solve this. I hope someone can help me.

EDIT: I tried logging in from the API side (locally) and it works. the problem is just the web side.

douji1077
douji1077 可悲的是没有:(
接近 2 年之前 回复
dqtiober37522
dqtiober37522 只需尝试使用phpartisankey:generate
大约 2 年之前 回复

3个回答



我遇到过同样的问题,尝试从项目目录运行以下命令:</ p>

< p> chmod 777 storage / framework / sessions / </ p>

我希望它对您有用!</ p>
</ div>

展开原文

原文

I have faced the same issue once, try to run the command below from the project directory:

chmod 777 storage/framework/sessions/

I hope it will work for you!

dsfh40613182
dsfh40613182 那没起效 :(
大约 2 年之前 回复

Try this

{{ csrf_field() }} to

<input type="hidden" name="_token" class="_token" value="{{ csrf_token() }}">
dpxkkhu1812
dpxkkhu1812 不。 不起作用
大约 2 年之前 回复

I found these steps from here: token mismatch

1). Remove 'SESSION_DRIVER' field from your .env 2). Go to your config/session.php and in domain mark the second parameter of env() to null i.e.

'domain' => env('SESSION_DOMAIN', null)

3). Run php artisan cache:config and php artisan cache:clear 4). Restart the server and clear your browser cache, and whoaa may be all things are up and running now.

dqe9657
dqe9657 你有没有能够解决这个问题?
接近 2 年之前 回复
douyan9398
douyan9398 我会试着谢谢!
大约 2 年之前 回复
dongyuchen0214
dongyuchen0214 这可能是一个很长的镜头,但请查看您的视图,并确保每个视图只调用一次csrf_field()或csrf_token()。 换句话说,清除它们全部,并尝试逐个系统地添加它们。 你可能会在某些地方复制它们。
大约 2 年之前 回复
dtttlua7165
dtttlua7165 没有。 这不起作用。 我已经尝试过了
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐