Ich hatte ein Problem mit Laravel 5.4 in POST-Routen.Laravel 5.4 TokenMismatchException (Chrome)
Beim Übermitteln des Formulars wurde der Fehler TokenMismatchException angezeigt.
Ich dachte, es ging um PrefixVariable, also öffnete ich this issue auf Github. Aber nachdem ich zu viel getestet habe und verschiedene Lösungen ausprobiert habe, habe ich herausgefunden, dass das Problem nicht von Prefix verursacht wurde.
Alles in Firefox ist OK, das Hauptproblem tritt in Chrom auf. Die Post-Routen funktionieren nur einmal, nach dem Senden des ersten Formulars, alle folgenden Anforderungen an die gleiche URL-Seite TokenMismatchException Fehler.
Ich habe versucht, folgende:
- Clearing Chrome Cookies und den Verlauf
- Lauf
php artisan cache:clear
Befehl - Serve Zum Ändern der Port
- Prevent Caching in PHP mit Header
- Prevent Caching in HTML mit Meta Tags
Aber das Problem besteht immer noch.
Was genau stimmt nicht ?! Es wäre zu schätzen, wenn Sie mir helfen.
Login Form:
<form method="post" action="{{route('login')}}">
{!! csrf_field() !!}
<div class="row">
<div class="col-xs-12">
<div class="form-group no-margin">
<div class="col-xs-6 col-md-10 col-md-offset-1">
<input name="username" type="text" class="form-control" placeholder="نام کاربری" value="{{old('username')}}">
</div>
</div>
<div class="form-group no-margin">
<div class="col-xs-6 col-md-10 col-md-offset-1">
<input name="password" type="password" class="form-control" placeholder="کلمه عبور">
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group no-margin">
<div class="col-xs-5 col-md-offset-1">
<input name="captcha" type="text" class="form-control" placeholder="کپچا">
</div>
<div class="col-xs-5 no-pad-right">
<img src="{{captcha_src('flat')}}" class="img-responsive">
</div>
</div>
</div>
<div class="col-xs-12 text-center">
<div class="form-group">
<button type="submit" class="btn btn-success btn-raised">ورود<div class="ripple-container"></div></button>
<button type="reset" class="btn btn-danger btn-raised">انصراف<div class="ripple-container"></div></button>
</div>
</div>
</div>
</form>
web.php
Route::group(['prefix' => config('system.ADMIN_PATH'), 'namespace' => 'Panel'], function(){
Route::get('/', function(){return redirect()->route('login');});
Route::get('/auth', '[email protected]')->name('login');
Route::post('/auth', '[email protected]')->name('check');
});
AuthController.php:
namespace App\Http\Controllers\Panel;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class AuthController extends Controller
{
public function Login(Request $request)
{
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
return view('admin.login');
}
public function Auth(Request $request)
{
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
dump($request->all());
echo "Received";
}
}
Was ist der Zweck dieser Header? –
@TobyMellor Nur verhindern, zwischenspeichern. Es gibt keinen Unterschied in der Ausgabe ohne Header. –