TokenMismatchException in VerifyCsrfToken.php line 53 in Laravel 5.1

前端 未结 13 1184
独厮守ぢ
独厮守ぢ 2020-12-11 16:47

When I try to login show me token error. I have checked token in view form it\'s right and when comment \\App\\Http\\Middleware\\VerifyCsrfToken::class, in the

相关标签:
13条回答
  • 2020-12-11 17:14

    Add <?php echo Form::token(); ?> in side the form.

    0 讨论(0)
  • 2020-12-11 17:16

    I used the following code. It is working perfectly.

    <?php echo csrf_token(); ?>
    
    0 讨论(0)
  • 2020-12-11 17:16

    I had the same problem. I am using Laravel 5.1.28, php 5.6.13
    After seeing the TokenMismatchException in VerifyCsrfToken, I searched the web for answers but none solved my problem.

    The page did send the token. The token values is also seen in the session file in the directory storage/framework/sessions (I disabled encryption to see it).

    Exhausted, I re-install laravel and use simple form for testing - it worked without token mismatch error.

    Moving my code to the newly installed laravel piece by piece, I finally found that the problem was caused by doctrine/dbal (I still do not know why).

    Removed it from composer.json and the problem disappeared.
    In the composer.json, token mismatch error was seen with the following line:

    "require": {
        ....
        "doctrine/dbal": "^2.5"
        ...
    },
    

    Your case may be different, but you may want to see if you change anything in composer.json that may be causing the problem.

    0 讨论(0)
  • 2020-12-11 17:17

    Edited:

    Since you are using Form builder remove this from your form. Laravel form builder automatically adds a hidden token field to your form when you do Form::open()

    So remove this line:

     <input type="hidden" name="_token" value="{{ csrf_token() }}">
    
    0 讨论(0)
  • 2020-12-11 17:20

    Adding {!! csrf_field() !!} solved my problem as shown below:

    <form action="#" method="post" class="form-horizontal" role="form">
    {!! csrf_field() !!}
    
    </form>
    

    If using Laravel Form helper such as below:

    {!! Form::open(array('class' => 'form-horizontal', 'role' => 'form')) !!}
    

    CSRF Code will be added automatically in your html script. Also make sure to view the source code in browser to be certain that a field such as below was indeed added.

    <input type="hidden" name="_token" value="dHWBudjTyha9AMr0SuV2ABq5NNK6bTIDZDXRWCBA">
    
    0 讨论(0)
  • 2020-12-11 17:25

    I have same problem while using this code

    <input type="hidden" name="_token" value="{!! csrf_token() !!}">
    
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    

    by changing it to {!! csrf_field() !!} solve my problem

    i'm on L5.1

    0 讨论(0)
提交回复
热议问题