2016-11-24 118 views
2

我是工作在我的項目通常,當我打刷新地看到,我只是在HTML頁面中做了更改,頁面顯示的左上角的「重定向到一個文本TokenMismatchException: http://localhost:8888/xxx「。它將我重定向到登錄頁面。當我點擊登錄時,'TokenMismatchException'錯誤顯示:enter image description hereLaravel 5.3 - 對每一個崗位請求

登錄表單具有隱藏的輸入_token,標題也有它。正如我所說的一切都很好。我一直在做這個項目2個月。這與文件權限有關嗎?

這是登錄表單。

<form class="form-horizontal" role="form" method="POST" action="{{ url('/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-7"> 
          <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-7"> 
          <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-8 col-md-offset-4"> 
          <button type="submit" class="btn btn-primary"> 
           Login 
          </button> 
          <a class="btn btn-link" href="{{ url('/password/reset') }}"> 
           Forgot Your Password? 
          </a> 
         </div> 
        </div> 


       </form> 

謝謝:)

+0

你如何輸出的隱藏輸入_token? – aceraven777

+0

我輸入令牌是這樣產生的:「」 –

+0

就像你怎麼輸出?你使用'''{{csrf_field()}}'''? – aceraven777

回答

3

後,我安裝一個新的副本laravel我就開始貼上我的舊文件送ee在哪裏會重新生成不匹配標記問題。 它下降到routes/web.php文件。有些東西導致了錯誤。 這是在路由/ web.php文件的php的開始標記之前的空格。 東西沒有引起我的注意。就像那個項目工作正常,但突然不再。

因爲我讀,該空間被認爲是一個輸出。檢查這樣的解釋: https://stackoverflow.com/a/4345822/6634389

2

你爲什麼不使用{{csrf_field()}}或與嘗試?

+0

是的,我在登錄表單上使用{{csrf_field()}}。 –

2

運行:

php artisan cache:clear; composer dump-autoload; composer clear-cache 

刷新瀏覽器,請確保您生成您的應用程序的關鍵。這應該工作。對我來說它的確如此。

+0

我試過了,沒有結果。 –

+0

用php artisan key生成另一個鍵:生成,關閉並打開瀏覽器,關閉服務器並再次打開它。但我真的認爲原因是你的cookies,清除你的瀏覽器緩存/ cookies並重試。 –

+0

我清除了緩存/ cookies,關閉服務器,密鑰生成。仍然沒有結果。我問,可能沒有任何要求發佈的工作?當他們在工作之前。我在mac上使用mamp。任何我應該看的地方? –

1

您刷新了您的網頁,所以每次頁面使用相同的CSRF令牌加載。因此,當您嘗試發佈數據時,laravel會拒絕它並提供錯誤消息,因爲每個請求都應該具有唯一的csrf標記。你可以閱讀這個在這裏laravekl csrf protection

要麼你應該再刷新頁面,或您應該通過評論它的

應用=>的Http => Kernel.php

內禁用CSRF保護

的$ middlewareGroups =>「網絡」內部

\App\Http\Middleware\VerifyCsrfToken::class, //comment this line 
+0

如果我禁用了VerifyCsrfToken,在每個帖子請求網站顯示:「重定向到http:// localhost:8888/xxx /」並重定向到頁面我發了帖子。 –

+0

檢查你的表單動作網址,你在你的控制器中的動作重定向到哪裏 –

+0

在控制器中的動作url和重定向是好的。一般來說,這與帖子有關。並不是只有一個表單發佈請求的錯誤。 –

1

我有同樣的問題,我解決它使用在我看來,以下

<input type="hidden" name="_token" value="{{ session()->getToken() }}">