Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Khudadad's avatar

TokenMismatchException

I'm using Laravel 5.1 When I want to submit the form of a post I get this error, how can I solve it. I'm using form facade that automatically add the token filed.

TokenMismatchException in VerifyCsrfToken.php line 53:

Thanks

0 likes
17 replies
davorminchorov's avatar

Browser? Is it Microsoft Edge? I had problems (and I still do) with token mismatch exceptions on it.

1 like
Equilibum's avatar

Check your config.php file please, maybe u have some problems there

coder's avatar

the general reason of this exception is that Laravel use a csrf_field() in the form to protect us from cross site forgery . which generates a hidden input like this

<input type="hidden" name="_token" value="RANDOM_TOKEN"/>

I think you didn't added {{ csrf_field() }} in you form view . so add it it this will work

Khudadad's avatar

I'm using Form Facade this input field is generated automatically.

RomainLanz's avatar

If you check the generated HTML code do you see the token?

Khudadad's avatar

Yes.

<input name="_token" type="hidden" value="ion7dCvI4OTRAv5WbeqotTTKdavN30QjXLMy4l7A">
RomainLanz's avatar

It's a little bit weird... If you don't use the HTMLFacade is it working?

coder's avatar

i know this sounds lil weird but just for checking remove the html package and require it again .

Khudadad's avatar

Thank you everyone I found the problem, when submitting the form the size of the image was so large, the error solved by small size of image.

1 like
puzbie's avatar

I was using this, and Edge seemed to ignore it.

$(function() {
        $.ajaxSetup({
            headers: {
                'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
            }
        });
    });

I solved it by adding the token to my ajax post data as well:

            postData._token = $('meta[name="csrf-token"]').attr('content');
AdrianB's avatar

Has anyone found a fix for Microsoft Edge issues causing the TokenMismatchException?

EDIT: My issue had to do with the server time being incorrect (40 minutes behind). Fixing this resolved all my session issues in IE and Edge.

Please or to participate in this conversation.