简体   繁体   中英

TokenMismatchException in Laravel 5.3 form

I feel ashamed asking this question as it has been asked many times by other people, however I cannot find any solution for myself.

I am using Laravel 5.3 and I created a simple form according to documentation and other stackoverflow topics.

Everything works fine in my local machine. After putting my project on server this error keeps showing up after I submit the form:

TokenMismatchException in VerifyCsrfToken.php line 68:

Added CSRF token in head section:

<head>
<meta name="csrf-token" content="{{ csrf_token() }}" />
</head>

Form also contains csrf:

 <form method="POST" action="/save_new_order">
       {{ csrf_field() }}
       <input type="text" name="web_name"> 
       <textarea cols="30" rows="15" name="web_description"></textarea>                  
       <input type="email" name="web_email"> 
       <input type="submit" id="submitButton" value="WYŚLIJ" name="submit">
    </form>

I also tried using:

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

instead of:

{{ csrf_field() }}

Tokens are being saved in storage/framework/sessions/ everytime I use the form.

Please help me on this, I am working for over 15 hours and nothing so far.

When it works on your local machine, but not on your live server, this could be a permission problem. Check Laravel's session directory and verify that you web-server user has rw rights.

Also, when you are using the same domain for your local and production server, try to clear your cookies. But you might have tried this already

I had invisible BOM character in my .env file.

I converted it to utf8-without-BOM in my notepad++ and it works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM