我是laravel框架的新手,我正在尝试为我的单页个人网站实现我自己的小型CMS。我正在使用laravel 5.2,其标准身份验证由php artisan make:auth
创建。在当地一切都很好。当我尝试登录时,在实时环境(Ubuntu服务器16.04)上会出现此问题。我得到了以下堆栈跟踪:
TokenMismatchException in VerifyCsrfToken.php line 67:
1. in VerifyCsrfToken.php line 67
2. at VerifyCsrfToken->handle(object(Request), object(Closure))
3. at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
4. at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
5. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
6. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
7. at ShareErrorsFromSession->handle(object(Request), object(Closure))
8. at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
9. at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
10. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
11. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 62
12. at StartSession->handle(object(Request), object(Closure))
13. at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
14. at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
15. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
16. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
17. at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
18. at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
19. at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
20. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
21. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
22. at EncryptCookies->handle(object(Request), object(Closure))
23. at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
24. at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
25. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
26. at Pipeline->Illuminate\Routing\{closure}(object(Request))
27. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
28. at Pipeline->then(object(Closure)) in Router.php line 726
29. at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
30. at Router->dispatchToRoute(object(Request)) in Router.php line 675
31. at Router->dispatch(object(Request)) in Kernel.php line 246
32. at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
33. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
34. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
35. at CheckForMaintenanceMode->handle(object(Request), object(Closure))
36. at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
37. at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
38. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
39. at Pipeline->Illuminate\Routing\{closure}(object(Request))
40. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
41. at Pipeline->then(object(Closure)) in Kernel.php line 132
42. at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
43. at Kernel->handle(object(Request)) in index.php line 54
ErrorException in Filesystem.php line 109:file_put_contents(/8c52f42d0453d6f2bbd07ea1aa65b77b90238995): failed to open stream: Permission denied
1. in Filesystem.php line 109
2. at HandleExceptions->handleError('2', 'file_put_contents(/8c52f42d0453d6f2bbd07ea1aa65b77b90238995): failed to open stream: Permission denied', '/var/www/laravel/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php', '109', array('path' => '/8c52f42d0453d6f2bbd07ea1aa65b77b90238995', 'contents' => 'a:3:{s:6:"_token";s:40:"Z5yxi65ubXWtVrZiMeU2yAGdJjxQs4xxNY7xU5Tx";s:9:"_sf2_meta";a:3:{s:1:"u";i:1473341363;s:1:"c";i:1473341363;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', 'lock' => true))
3. at file_put_contents('/8c52f42d0453d6f2bbd07ea1aa65b77b90238995', 'a:3:{s:6:"_token";s:40:"Z5yxi65ubXWtVrZiMeU2yAGdJjxQs4xxNY7xU5Tx";s:9:"_sf2_meta";a:3:{s:1:"u";i:1473341363;s:1:"c";i:1473341363;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', '2') in Filesystem.php line 109
4. at Filesystem->put('/8c52f42d0453d6f2bbd07ea1aa65b77b90238995', 'a:3:{s:6:"_token";s:40:"Z5yxi65ubXWtVrZiMeU2yAGdJjxQs4xxNY7xU5Tx";s:9:"_sf2_meta";a:3:{s:1:"u";i:1473341363;s:1:"c";i:1473341363;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', true) inFileSessionHandler.php line 71
5. at FileSessionHandler->write('8c52f42d0453d6f2bbd07ea1aa65b77b90238995', 'a:3:{s:6:"_token";s:40:"Z5yxi65ubXWtVrZiMeU2yAGdJjxQs4xxNY7xU5Tx";s:9:"_sf2_meta";a:3:{s:1:"u";i:1473341363;s:1:"c";i:1473341363;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}') in Store.php line 262
6. at Store->save() in StartSession.php line 88
7. at StartSession->terminate(object(Request), object(Response)) in Kernel.php line 155
8. at Kernel->terminate(object(Request), object(Response)) in index.php line 58
这是我的路线
Route::get('/', 'FrontendController@index');
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/admin', 'AdminController@index');
Route::get('/profile', 'AdminController@editProfile');
Route::put('/profile/update', 'AdminController@updateProfile');
Route::get('/page', 'PageController@index');
Route::put('/page/update', 'PageController@update');
Route::resource('aboutItems', 'AboutItemsController');
Route::resource('portfolioItems', 'PortfolioItemsController');
});
登录表单:
<div class="login login-v2" data-pageload-addclass="animated fadeIn">
<div class="login-content">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
{!! csrf_field() !!}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn"></i>Login
</button>
</div>
</div>
</form>
我做过/尝试过的事情:
答案 0 :(得分:0)
我在下面的视图文件中使用csrf字段,如下面的方式来形成标记。
<input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
试试这个,希望这会有所帮助。
答案 1 :(得分:0)
我将我的项目升级到5.3,现在一切似乎都在我的VPS上工作正常。我仍然不知道实际问题是什么。安装Laravel或身份验证时可能出现问题。