2016-11-18 34 views
2

我使用Auth中構建的Laravels。需要改變一些路徑和東西。一切在一開始就運行良好。但我注意到我會隨機註銷。 Laravel將mit返回到登錄頁面。另外,有時,當我嘗試登錄有,三種不同的事情都可能發生,我不知道爲什麼:Laravel自動註銷並且有時令牌不匹配

  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> 

可能是什麼問題?

回答

0

看起來這是會話的一些問題,您在哪個Laravel版本上工作?

事情你需要檢查,以確保會議運作良好:

  • 請確保您有對/存儲/ *目錄適當的權限。
  • 在您的項目上搜索session() - > flush(),它會銷燬當前會話。
  • 請記住,如果你做了dd()die()當你存儲一個會話時,它不會被存儲。
  • 您需要安裝這個PHP擴展:
    • MBSTRING
    • 標記者
  • 會議中間件是正確的加載順序:

App \ Ht TP \ 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, 
    ], 

]; 

如果你能提供更多的信息,我可以試着幫你多,希望它可以幫助你:)