当我尝试在 Laravel 5.2 中使用 auth 时出现此错误。那是在移动到实时服务器之后发生的。在我的本地服务器上一切正常。
Token inside form 和 is Session:token() 是一样的。
更新:我把 dd($request) 放在 laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php
并且 _token 值不匹配表单中的 _token 输入。
我试过:
- 为 auth 路由禁用 CSRF,在 except 数组中添加路由
Midd/VerifyCsrfToken.php。
- 为/storage/bootstrap 文件夹设置 777 权限。
- 用过{!! csrf_field() !!} 和 name="_token"value="{{ csrf_token() }}">.
- 更改了 config/session.php 中的域。
- php artisan key:generate.
- 重新安装 Auth。 还有我有 middleware = auth.basic 的路由,即使一开始没有要求登录,我也会收到“无效凭据”。
在我的本地服务器上它工作正常。
最佳答案
你的handler是这样的吗?
<?php
...
public function handle( $request, Closure $next )
{
if (
$this->isReading($request) ||
//$this->runningUnitTests() ||
$this->shouldPassThrough($request) ||
$this->tokensMatch($request)
) {
return $this->addCookieToResponse($request, $next($request));
}
// redirect the user back to the last page and show error
return Redirect::back()->withErrors('Sorry, we could not verify your request. Please try again. (You waited too long to submit your form)');
}
关于php - 仅在实时服务器上 VerifyCsrfToken.php 第 67 行中的 TokenMismatchException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40282316/