【问题标题】:Laravel Automatic Logout and sometimes Token MismatchLaravel 自动注销,有时令牌不匹配
【发布时间】:2017-04-02 08:09:10
【问题描述】:

我使用了内置于 Auth 的 Laravel。需要改变一些路径和东西。一开始一切都很好。但我注意到我被随机注销了。 Laravel 将 mit 返回到登录页面。另外,有时当我尝试在那里登录时,可能会发生三种不同的事情,我不知道为什么:

  1. 页面重新加载,输入消失
  2. 令牌不匹配错误
  3. 已登录

这是我的登录视图:

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

     <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
         <label for="email" class="col-md-4 control-label">@lang('admin/login.mail')</label>

         <div class="col-md-12">
             <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">@lang('admin/login.password')</label>

         <div class="col-md-12">
                <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-2 col-md-offset-5">
            <button type="submit" class="btn btn-primary">
                Login
            </button>
        </div>
    </div>
</form>

可能是什么问题?

【问题讨论】:

    标签: php laravel authentication


    【解决方案1】:

    Session 似乎有问题,您正在使用哪个 Laravel 版本?

    您需要检查以确保会话正常运行:

    • 确保您对 /storage/* 目录具有适当的权限。
    • 在您的项目中搜索 session()->flush(),它会破坏当前会话。
    • 请记住,如果您在存储会话时执行 dd()die(),它将不会被存储。
    • 您需要安装此 PHP 扩展:
      • Mbstring
      • 分词器
    • 会话 middleware 处于正确的加载程序顺序:

    App\Http\Kernel.php上,这是默认的内核中间件顺序(Laravel 5.3)

    /**
     * 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,
        ],
    
    ];
    

    如果您能提供更多信息,我可以尝试为您提供更多帮助,希望对您有所帮助:)

    【讨论】:

    • 我目前有这个问题,随机注销。我的函数注销时有会话刷新。是这样吗?
    猜你喜欢
    • 2016-10-24
    • 2020-02-12
    • 2020-07-08
    • 2016-12-10
    • 2016-09-20
    • 2020-01-20
    • 2017-05-23
    • 2016-12-06
    相关资源
    最近更新 更多