0

I know that this is an issue largely discussed and I have read a lot of posts about this but cannot find a solution.

I have developed a site locally on my PC and everything runs beautifully. I then put the site on my personal site to see how it would function. Upon doing this everything seemed to work except the Authentication part of my site. When I try to log in to my application I receive this error TokenMismatchException in VerifyCsrfToken.php line 46

I did not get this error locally but receive it when it is on my host server. Is there something I missed? need to change in a config file?

I have updated my .env, app.php, database.php files to run with my personal site. I made sure that this <input type="hidden" name="_token" value="{{ csrf_token() }}"> element was right under my <form> tag as seen from other posts with this similar problem.

Ideas?

HTML:

<form class="form-horizontal" role="form" method="POST" action="">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
IE5Master
  • 413
  • 1
  • 3
  • 14
  • Try to clear your cache, then run `php artisan key:generate`, and make sure the generated key is placed in your .env file. – Mina Abadir Dec 05 '15 at 05:40
  • @MinaYoussef Your suggestion seemed to work perfect for me. Please create a new answer so that I may select it as correct. Thank you very much for your help – IE5Master Dec 06 '15 at 18:59
  • Oh I am glad it worked, I have created the answer. – Mina Abadir Dec 06 '15 at 19:04

3 Answers3

1

Try to perform the following:

  1. Clear your cache
  2. Run php artisan key:generate
  3. Make sure the generated key is placed in your .env file.
Mina Abadir
  • 2,951
  • 2
  • 15
  • 20
0

If You are posting form using jquery then you should include csrf_token()

$_token = "{{ csrf_token() }}";
$.post( 'myurl', { param1: $param1, param2: $param2, _token: $_token })
.done(function( data )
{
     console.log('Done!');
});

And if you are posting the form directly and facing the same problem then goto app/Http/Resquests/Kernel.php and comment this line

\App\Http\Middleware\VerifyCsrfToken::class
0

See this answer and avoid doing what suggested above all the time.

jQuery add CSRF token to all $.post() requests' data

Community
  • 1
  • 1
Tim van Uum
  • 1,873
  • 1
  • 17
  • 36