2015-10-07 131 views
0

我在laravel中使用HTML頁面作爲UI目的,當我嘗試登錄時,它顯示錯誤頁面「TokenMismatchException in VerifyCsrfToken.php line 53:」。 我在登錄以及註冊時出現此錯誤。 我有login.html的頁面如下:TokenMismatchException在VerifyCsrfToken.php第53行Laravel 5

<div class="container"> 

<form method="POST" action="login_display" accept-charset="UTF-8"> 

    <h1>Login</h1> 

    <hr> 

    <div class="form-group"> 

     <label for="email">Email ID :</label> 

     <input class="form-control" name="email" type="text" id="email" placeholder="Please enter email here"> 

    </div> 

    <div class="form-group"> 

     <label for="password">Password :</label> 

     <input class="form-control" name="password" type="password" value="" id="password" placeholder="Please enter password here"> 

    </div> 

    <div class="form-group"> 

     <input class="btn btn-primary form-control" type="submit" value="Login"> 

    </div> 

</form> 

</div> 
+1

[Laravel 5.1中的VerifyCsrfToken.php第53行中的TokenMismatchException]的可能重複(http://stackoverflow.com/questions/30934906/tokenmismatchexception-in-verifycsrftoken-php-line-53-in-laravel-5-1 ) – aldrin27

+0

您沒有包含表單中的csrf標記。 http://laravel.com/docs/5.0/routing#csrf-protection –

回答

2

嘗試增加,<input type="hidden" name="_token" value="{{ csrf_token() }}">到表單中。 Laravel使用此標記來檢查表單提交是否有效。

+0

Thanku,它的工作原理... – Amarja

+0

我有一個問題要問....昨天我嘗試通過添加這一行到我的HTML頁面,它的工作很好,但現在它顯示了同樣的錯誤頁面。 – Amarja

+0

csrf令牌在會話中持續2個小時,在此之後,您需要獲取新令牌(這意味着刷新頁面),否則您的表單提交將失敗。我通常通過捕獲TokenMismatchException來處理這個問題,並使用類似'redirect() - > back() - > withInput() - > withErrors(['token_mismatch'=>'您是否已經離開?請嘗試再次提交表單!']);' –

1

我試圖通過添加以下行形式:

<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"> 

這一次,它工作得很好,我沒有得到TokenMismatchException錯誤之後也是如此。

相關問題