Laravel 5.2:CSRF令牌不起作用 [英] Laravel 5.2 : csrf token doesn't work

查看:284
本文介绍了Laravel 5.2:CSRF令牌不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的csrf令牌值为null?当我不使用令牌时,我没有TokenMismatchException !!!!我该如何解决?

Hi Why my csrf token value is null ? And when i don't use token i havent TokenMismatchException!!!! how can i fix it ?

>

我更深入地研究发现会话未在SessionServiceProvider中注册.是否需要启用某些功能才能使其默认运行?由于我是Laravel的初学者,因此我不确定如何遵循上述建议.如何确保将我的路线添加到网络"组下?

I dug deeper and found that a session is not being registered in SessionServiceProvider. Is there something that needs to be enabled for this to work by default? Since I am a Laravel beginner, I am not sure how to follow the advice above. How do I make sure that my routes are added under the "web" group?

<form method="post" action="<?php echo url('/form'); ?>">
    <input type="hidden" name="_Token" value="{{ csrf_token() }}">
    <input type="text" name="Title" placeholder="Title"><br>
    <textarea rows="10" name="Content" placeholder="Content"></textarea><br>
    <input type="submit" value="Send">
</form>

推荐答案

请确保您的路线已应用 web 防盗软件.

Make sure your route has the web milddleware applied to it.

几乎所有您需要会话,csrf保护,加密的cookie,会话错误等的路由……您都需要应用网络"中间件组.

Pretty much any route where you will want sessions, csrf protection, encrypted cookies, session errors, etc ... you will need the 'web' middleware group applied.

像下面那样检查您的route.php文件中的路由组:

Check your routes.php file for the route group like so:

Route::group(['middleware' => 'web'], function () {
    //
});

更新:从5.2.27开始,RouteServiceProvider现在将您的所有路由放入已应用了web中间件的路由组的routes.php中.

Update: Since 5.2.27 The RouteServiceProvider now puts all your routes in routes.php in a route group that has the web middleware applied for you.

这篇关于Laravel 5.2:CSRF令牌不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆