0

I am using HTML pages for UI purpose in laravel and when I try to login then it shows me an error page "TokenMismatchException in VerifyCsrfToken.php line 53:". I am getting this error while login as well as registration. I have the login.html page as follows:

<div class="container">

<form method="POST" action="login_display" accept-charset="UTF-8">

    <h1>Login</h1>

    <hr>

    <div class="form-group">

        <label for="email">Email ID :</label>

        <input class="form-control" name="email" type="text" id="email" placeholder="Please enter email here">

    </div>

    <div class="form-group">

        <label for="password">Password :</label>

        <input  class="form-control" name="password" type="password" value="" id="password" placeholder="Please enter password here">

    </div>

    <div class="form-group">

        <input class="btn btn-primary form-control" type="submit" value="Login">

    </div>

</form>

</div>
AmarjaPatil4
  • 1,640
  • 3
  • 28
  • 41
  • 1
    Possible duplicate of [TokenMismatchException in VerifyCsrfToken.php line 53 in Laravel 5.1](http://stackoverflow.com/questions/30934906/tokenmismatchexception-in-verifycsrftoken-php-line-53-in-laravel-5-1) – aldrin27 Oct 07 '15 at 09:29
  • You did not inlcude the csrf token in your form. http://laravel.com/docs/5.0/routing#csrf-protection – shock_gone_wild Oct 07 '15 at 10:35

2 Answers2

2

Try adding, <input type="hidden" name="_token" value="{{ csrf_token() }}"> to your form. Laravel uses this token to check that the form submission was valid.

craig_h
  • 31,871
  • 6
  • 59
  • 68
  • I had a question to ask.... Yesterday I tried by adding this line to my html page and it worked fine but now today it shows me the same error page. – AmarjaPatil4 Oct 08 '15 at 07:22
  • The csrf token lasts in the session for 2 hours, after this point you need to get a new token (which simply means refreshing the page) otherwise your form submission will fail. I usually handle this by catching the `TokenMismatchException` and use something like `redirect()->back()->withInput()->withErrors(['token_mismatch' => 'Have you been away? Please try submitting the form again!']);` – craig_h Oct 08 '15 at 09:34
1

I tried by adding following line to the form:

    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">

and this time it works well and I didn't get the TokenMismatchException error afterwards as well.

AmarjaPatil4
  • 1,640
  • 3
  • 28
  • 41