Token Mismatch Exception,如果表单在浏览器中长时间打开

时间:2016-08-09 06:01:10

标签: php laravel frameworks token

我知道什么是TokenMismatchException exeptions但是我如何解决问题如果一个表单打开了很长时间然后突然你填写表单并提交它然后它也会抛出相同的TokenMismatchException,有没有解决方案没有显示这样的如果表单页面长时间保留偶像然后提交,会话将在一段时间后过期。就是这样。

2 个答案:

答案 0 :(得分:0)

您必须在应用程序的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,

答案 1 :(得分:0)

您需要在app \ Exceptions \ Handler.php中添加TokenMismatchException

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 
        .
        .
        .
        .

    }

}