【问题标题】:Laravel 5, Forms, TokenMismatchException in VerifyCsrfToken.php line 46Laravel 5,表单,VerifyCsrfToken.php 第 46 行中的 TokenMismatchException
【发布时间】:2015-05-21 02:42:38
【问题描述】:

提交表单时,我不断收到“VerifyCsrfToken.php 第 46 行中的 TokenMismatchException”错误。

这是其中一种形式:

{!! Form::model($product, array('url' => 'product/'.$product->id, 'class' => 'form', 'method' => 'PATCH')) !!}

<div class="form-group">
    {!! Form::textarea('note', $product->note,
        array('class'=>'form-control', 'id'=>'product-note', 'placeholder'=>Lang::get('customtranslation.form_placeholder_note'), 'rows'=>3)) !!}
    <br />
    <span class="btn btn-link" id="remove-note" role="button"><i class="fa fa-times"></i> {{ Lang::get('customtranslation.button_txt_reset_note') }}</span>
</div>

<div class="form-group">
    {!! Form::submit(Lang::get('customtranslation.button_txt_finish_edit_product'), array('class'=>'btn btn-success')) !!}
</div>

<div class="form-group">
    <!-- Custom tags -->
    {!! Form::label('additional-tags', Lang::get('customtranslation.form_edit_label_additional_tags')) !!}
    {!! Form::text('additional-tags','', array('id'=>'additional-tags', 'data-role'=>'tagsinput')) !!}
</div>

{!! Form::close() !!}

名称为“_token”的输入元素按预期生成和设置。

奇怪的是,这只发生在 Internet Explorer (IE11) 中。 Chrome 和 FF 可以毫无问题地提交。

还有其他人有这个问题和可能的解决方案吗?

【问题讨论】:

  • 调试您的应用程序并确保您在请求中获得了 _token 参数。
  • 向我们展示该表单的代码
  • 谢谢大家的回复。我已经用生成表单的代码更新了我的问题。该问题仅在 Internet Explorer 中出现。
  • 您的域名中是否有下划线?喜欢local_host
  • @Chris 里面有一个下划线。我已将下划线更改为连字符,现在一切正常。感谢您的提示:)

标签: laravel laravel-5


【解决方案1】:

Internet Explorer 拒绝来自带有下划线的域的会话。这是一个已知的问题。

请看这里:Issue with Session and Cookie in Internet Explorer for websites containing underscore

还有: http://blogs.msdn.com/b/ieinternals/archive/2009/08/20/wininet-ie-cookie-internals-faq.aspx

【讨论】:

  • 我在 chrome 中也有这个问题,在 FF 表单中也可以正常工作,有什么解决方案吗?
  • @Adamnick 这是一个非常常见的问题(令牌不匹配),通常源于对令牌试图做什么的误解。通常上面的答案不是解决方案(这个只涵盖了 IE 问题)。如果您遇到令牌不匹配问题,我建议您提出自己的问题并将我链接到它,以便我查看
【解决方案2】:

可能你在对服务器的请求中没有设置_token参数,或者你把它放在了不正确的地方。

【讨论】:

  • _token 由 Laravel 自动生成。
猜你喜欢
  • 2015-08-19
  • 2015-05-06
  • 2015-06-22
  • 2016-07-27
  • 2015-08-08
  • 2016-01-04
  • 1970-01-01
  • 2016-03-20
  • 1970-01-01
相关资源
最近更新 更多