【问题标题】:TokenMisMatchException in Laravel AuthLaravel 身份验证中的 TokenMisMatchException
【发布时间】:2019-09-06 21:11:08
【问题描述】:

我安装了新的 laravel 5.8。 之后我跑了:

 php artisan make:auth

一切看起来都很好,但是当我尝试登录时(例如:用不正确的值填写表格) 我得到 "TokenMismatchException in VerifyCsrfToken.php line 68" 错误。

我在每个身份验证表单中都遇到了这些异常!

我的观点(登录):

 <form class="form-horizontal" method="POST" action="{{ route('login') }}">

                       {{ csrf_field() }}


                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label for="email" class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-8 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Login
                                </button>

                                <a class="btn btn-link" href="{{ route('password.request') }}">
                                    Forgot Your Password?
                                </a>
                            </div>
                        </div>

                    </form>

我不知道怎么回事,但是 laravel 在 artisan 命令之后崩溃了……

从 {{csrf_field()}} 更改为 {!! csrf_field() !!} 已经尝试过了。不工作...

【问题讨论】:

    标签: laravel exception laravel-5 login


    【解决方案1】:

    我在 plesk 上运行我的 laravel。为了解决这个问题,我只是将存储和子文件夹权限更改为 777,并使用 nginx 将版本从 php 7.2 更新为 php 7.2。

    【讨论】:

    • 您不应使用777 权限。使用755,对于像.env 这样的私人文件使用640
    • 请使用您问题上的编辑链接添加其他信息。 Post Answer 按钮应仅用于问题的完整答案。 - From Review
    • @Jamesking56 请不要单独将“更新”作为更新的标志。这是一个答案,答案不会在编辑中进行。
    • @Zoe 它需要更新说明为什么要使用这些权限,并附有引用。
    • @Jamesking56 这不是维基百科 - 原始内容不需要来源(复制粘贴的内容需要署名和其他一些东西,但这似乎不是从任何地方复制粘贴的)
    【解决方案2】:

    编辑:这个答案是关于{{ csrf_token() }} 而不是{{ csrf_field() }}。尽管它不是答案,但它可能会有所帮助。

    {{ csrf_token() }} 值添加到属性名称为name="_token" 的隐藏输入中:

      <form class="form-horizontal" method="POST" action="{{ route('login') }}">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
    
                                ...
    

    或使用@csrf Blade 指令:

      <form class="form-horizontal" method="POST" action="{{ route('login') }}">
        @csrf
    

    【讨论】:

    • 这是一个权限和 php 错误。答案贴在下面。谢谢:)
    • 操作,我的错。我弄错了,我读为csrf_token()。我知道这不是答案,但我还是要编辑它。
    猜你喜欢
    • 2016-09-01
    • 2016-05-16
    • 2016-08-03
    • 2019-08-12
    • 2016-08-05
    • 1970-01-01
    • 2019-10-10
    相关资源
    最近更新 更多