2017-09-14 83 views
0

我爲我的應用程序使用larvel 5.2,我沒有使用laravel身份驗證並編寫自己的代碼,在成功登錄時我將用戶名存儲在會話變量中並檢查爲登錄後的每個請求。我沒有更改任何會話設置。我的問題是會在每種不超過3mins到期,有時同時登錄它顯示會話在laravel 5.2中自動過期

TokenMismatchException in VerifyCsrfToken.php line 67:

只記得有時。刷新頁面後,一切正常,3分鐘內登錄後即可過期。我在航線代碼如下,

Route::get('/', function() { 
    if(Session::has('username') && Session::get('username') != ""){ 
     return view('index'); 
    } 
    else{ 
     return redirect('login'); 
    } 
}); 
Route::get('login', function() { 
    if(Session::has('username') && Session::get('username') != ""){ 
     return redirect('/'); 
    } 
    else{ 
     return view('login'); 
    } 
}); 

我的登錄和會話存儲的,

public function checkme(Request $request){ 

    $this->validate($request, [ 
     'username' => 'required', 
     'password' => 'required' 
    ]); 

    //return $request->all(); 
    $username = $request->username; 
    $password = md5($request->password); 

    $admin = Admin::where('username', $username) 
       ->where('password', $password) 
       ->where('status', 'active') 
       ->first(); 

    if(is_null($admin)){ 

     Session::flash('Invalid','Invalid Credentials..!'); 
     return redirect('login'); 
    } 
    else{ 

     Session::put('username',$admin->username); 
     return redirect('/'); 
    } 

} 

我的登錄表單代碼,

<form class="login" method="post" action="login"> 
        <input type="hidden" name="_token" value="<% csrf_token() %>"> 
        <input type="text" placeholder="Username" name="username" required="true" /> 
        <input type="password" name="password" placeholder="Password" required="true" /> 
        <input type="submit" value="Login" class="btn btn-info btn-sm" /> 
       </form> 
+0

分享您將用戶放入會話的部分? – C2486

+0

@ user2486我更新了我的問題。 – prudhvi259

+0

分享您的登錄狀態代碼 –

回答

0

我得到了解決辦法,但它似乎很奇怪我。 在config/session.php
我改變了這種
'cookie' => 'laravel_session',

'cookie' => 'myapp_session',
我從laracasts這個建議點擊link here
我仍然感到奇怪這件事,如果有人知道這個問題背後的原因,請讓我知道。