令牌不匹配异常,如果表单在浏览器中打开了很长时间
Token Mismatch Exception , if a form is open in browser for long time
我知道什么是 TokenMismatchException 异常,但是如果表单打开了很长时间然后突然填写表单并提交然后它也抛出相同的 TokenMismatchException,我如何解决这个问题,有没有解决方案show such an error.The session expires after some time if the form page is left idol long time and submit it.仅此而已。
您必须在应用程序的 config/session.php
文件中增加会话时间。
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 120,
'expire_on_close' => false,
您需要在app\Exceptions\Handler中添加TokenMismatchException。php
use Illuminate\Session\TokenMismatchException;
class Handler extends ExceptionHandler {
public function render($request, Exception $e) {
if ($e instanceof TokenMismatchException){
//redirect to a form when there is token mismatch
return redirect($request->fullUrl())->with('alert-warning',"Opps! Seems you couldn't submit form for a longtime. Please try again");
}
//Remaining code
.
.
.
.
}
}
我知道什么是 TokenMismatchException 异常,但是如果表单打开了很长时间然后突然填写表单并提交然后它也抛出相同的 TokenMismatchException,我如何解决这个问题,有没有解决方案show such an error.The session expires after some time if the form page is left idol long time and submit it.仅此而已。
您必须在应用程序的 config/session.php
文件中增加会话时间。
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 120,
'expire_on_close' => false,
您需要在app\Exceptions\Handler中添加TokenMismatchException。php
use Illuminate\Session\TokenMismatchException;
class Handler extends ExceptionHandler {
public function render($request, Exception $e) {
if ($e instanceof TokenMismatchException){
//redirect to a form when there is token mismatch
return redirect($request->fullUrl())->with('alert-warning',"Opps! Seems you couldn't submit form for a longtime. Please try again");
}
//Remaining code
.
.
.
.
}
}