<form action="/admin/upload" enctype="multipart/form-data" method="post">
<input type="file" name="image" /> <br>
<input type="text" name="name" /> <br>
<input type="text" name="email" /> <br>
<input type="text" value='{:token()}' name="__token__" style="width:400px;"><br>
<input type="submit" value="上传" />
</form>没提交前 能dump到 array:2 [▼
"testSession" => "testValue"
"__token__" => "36ee48ab50126f38dedb8f0398599c30"
]
中间件也开启了。
// Session初始化,不启用则
\think\middleware\SessionInit::class,
// 定义Token中间件
\think\middleware\FormTokenCheck::class,提交表单后,没有了。一直提示无效令牌dump出来的session 为 null
namespace app\admin\controller;
use app\BaseController;
use think\facade\Session;
use think\Request;
use think\exception\ValidateException;
class Upload extends BaseController
{ public function Index(Request $request){
dump (Session::all()); //dump 不到。
$check = $request->checkToken('__token__');
if(false === $check) {
echo '令牌无效';
// throw new ValidateException('invalid token');
}请大神指点。谢谢。。 最佳答案