Laravel 5.4 TokenMismatchException in VerifyCsrfToken.php line 68 on some device

别等时光非礼了梦想. 提交于 2020-01-01 19:36:59

问题


I know it's one of the most asked question around here, but I really read everything on the first 10 pages results on google and nothing solved my problem.

On a fresh installation of laravel 5.4 , generated the auth controller, views, etc. via php artisan make:auth when I try to register (or login) in some device I get the following error:

TokenMismatchException in VerifyCsrfToken.php line 68

I'm running this application in local on debian 8.7 and php7 (could it be related to the problem in some way ?) From my pc, iphone 7, another windows 10 desktop it works perfectly, but on a Huawei p8 lite, ipad 2 and lubuntu (quite old version) I get that error. So it's really weird because it just happends with some device (no matter whaht O.S. no matter what browser).

I can already tell you that I tried grant permissions to sessions folder, change session_domain, clearing cache (but as I said I'm trying this on a fresh installation), change {{ csrf_token }} to {!! csrf_token !!} , etc.

Just to give you more information about my system, this is the php version i'm using:

php --version
PHP 7.0.17-1~dotdeb+8.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.17-1~dotdeb+8.1, Copyright (c) 1999-2017, by Zend 
Technologies

I'm really stuck on this for days. Got no more ideas.


回答1:


I'm assuming you added $this->middleware('auth'); inside the constructor of your controller to get the authentication working. Add the following at the top as well, under your login/register forms, if you are using {!! Form::someElement !!}:

{!! csrf_field() !!}

Or if you are using input tags inside your forms, just add this just after the <form> tag:

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



回答2:


in your .env file add

SESSION_DOMAIN=yourdomain.com


来源:https://stackoverflow.com/questions/43156466/laravel-5-4-tokenmismatchexception-in-verifycsrftoken-php-line-68-on-some-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!