在VerifyCsrfToken.php第46行中的TokenMismatchException偶尔显示

时间:2016-03-22 15:59:12

标签: php laravel-5

我已经在表单中设置了令牌:

<form action="{{ route('user.store') }}" method="post">
            <input type="hidden" name="_token" value="{!! csrf_token() !!}">
        <legend>Agregar nuevo usuario.</legend>

            <div class="form-group">
                <label>C&oacute;digo empresa</label>
                <input type="number" class="form-control input-sm" name="enterprise" id="enterprise">
            </div>
            <div class="form-group">
                <label>Nombre</label>
                <input type="text" class="form-control input-sm" name="name" id="name">
            </div>
            <div class="form-group">
                <label>Email</label>
                <input type="email" class="form-control input-sm" name="email" id="email">
            </div>
            <div class="form-group">
                <label>Usuario</label>
                <input type="text" class="form-control input-sm" name="username" id="username">
            </div>
            <div class="form-group">
                <label>Password</label>
                <input type="password" class="form-control input-sm" name="password" id="password">
            </div>
            <div class="form-group">
                <label class="checkbox-inline">
                    <input type="checkbox" name="create_content" id="create_content"> Crea contenido
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" name="active" id="active"> Activo
                </label>
            </div>

            <button type="submit" class="btn btn-sm btn-primary" id="btn_Crear">Create</button>
        </form>

我偶尔会收到TokenmismathException,而且我再也无法发帖了,如果我在Kernel.php文件中注释掉//'App\Http\Middleware\VerifyCsrfToken',行并尝试发帖,它可以正常运行,如果我再次取消注释相同的行'App\Http\Middleware\VerifyCsrfToken',,现在我不会收到TokenmismatchException,直到它停止工作。 我没有使用ajax 有谁知道为什么会这样。

1 个答案:

答案 0 :(得分:1)

我们遇到了完全相同的问题,从未找到一个好的解决方案。我们确实找到了解决方法。

在.env文件中,将会话存储设置为Redis(是的,您必须在服务器上安装Redis)。这对我们有用,再也没遇到过同样的问题。

请注意,这对我们有用,但它当然不是解决方案,只是在有人找到正确的解决方案之前解决。