<tfoot id='L0h2O'></tfoot>

  • <small id='L0h2O'></small><noframes id='L0h2O'>

      • <bdo id='L0h2O'></bdo><ul id='L0h2O'></ul>

        <legend id='L0h2O'><style id='L0h2O'><dir id='L0h2O'><q id='L0h2O'></q></dir></style></legend>
      1. <i id='L0h2O'><tr id='L0h2O'><dt id='L0h2O'><q id='L0h2O'><span id='L0h2O'><b id='L0h2O'><form id='L0h2O'><ins id='L0h2O'></ins><ul id='L0h2O'></ul><sub id='L0h2O'></sub></form><legend id='L0h2O'></legend><bdo id='L0h2O'><pre id='L0h2O'><center id='L0h2O'></center></pre></bdo></b><th id='L0h2O'></th></span></q></dt></tr></i><div id='L0h2O'><tfoot id='L0h2O'></tfoot><dl id='L0h2O'><fieldset id='L0h2O'></fieldset></dl></div>

        针对 AJAX 请求的 Yii 2.0 CSRF 验证

        Yii 2.0 CSRF validation for AJAX request(针对 AJAX 请求的 Yii 2.0 CSRF 验证)
        <legend id='qggtx'><style id='qggtx'><dir id='qggtx'><q id='qggtx'></q></dir></style></legend>
        <i id='qggtx'><tr id='qggtx'><dt id='qggtx'><q id='qggtx'><span id='qggtx'><b id='qggtx'><form id='qggtx'><ins id='qggtx'></ins><ul id='qggtx'></ul><sub id='qggtx'></sub></form><legend id='qggtx'></legend><bdo id='qggtx'><pre id='qggtx'><center id='qggtx'></center></pre></bdo></b><th id='qggtx'></th></span></q></dt></tr></i><div id='qggtx'><tfoot id='qggtx'></tfoot><dl id='qggtx'><fieldset id='qggtx'></fieldset></dl></div>

        <small id='qggtx'></small><noframes id='qggtx'>

          <tbody id='qggtx'></tbody>

          <tfoot id='qggtx'></tfoot>
                  <bdo id='qggtx'></bdo><ul id='qggtx'></ul>
                  本文介绍了针对 AJAX 请求的 Yii 2.0 CSRF 验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 ajax 函数,可以触发从我的数据库中删除条目.

                  I have an ajax function that triggers an entry deletion from my database.

                  我需要为此做 CSRF 验证.我该怎么做?

                  I need to do CSRF validation for the same. How can I do that?

                  我将 CSRF cookie 与我的 post 请求一起发送,但是 Yii 2.0 没有验证它,任何通过 ajax 传递的输入都到达了服务器.

                  I am sending the CSRF cookie along with my post request, but Yii 2.0 is not validating it and any input that is passed through ajax is reaching the server.

                  如何对ajax请求进行CSRF验证.

                  How do I do CSRF validation for ajax requests.

                  是否需要手动设置cookie并检查?

                  Whether we need to manually set cookie and check?

                  推荐答案

                  您无需手动设置 cookie.

                  You don't need to manually set cookie.

                  如果您使用 jQuery,CSRF 令牌将自动发送.

                  If you are using jQuery CSRF token will be sent automatically.

                  例如对于 AngularJS,您可以手动添加它以请求这样的参数:

                  For example for AngularJS you can add it manually to request params like that:

                  yii.getCsrfParam(): yii.getCsrfToken()
                  

                  确保你包含了 YiiAsset.

                  否则你可以从元标记中检索它们(这基本上就是这两种方法所做的):

                  Otherwise you can retrieve them from meta tags (that's basically what these two methods do):

                  $('meta[name=csrf-param]').prop('content'): $('meta[name=csrf-token]').prop('content')
                  

                  另请注意,要启用 CSRF 验证,ControllerRequest 的属性 enableCsrfValidation 必须设置为 true.

                  Also note that for enabling CSRF validation both Controller's and Request's property enableCsrfValidation property must be set to true.

                  更新:

                  另一个需要了解的重要事项:

                  Another important thing to understand:

                  CSRF 令牌将仅在以下方法上进行验证:GETHEADOPTIONS.

                  CSRF token will be validated only on this methods: GET, HEAD, OPTIONS.

                  还要确保在主布局中有 <?= Html::csrfMetaTags ?>.

                  Also make sure you have <?= Html::csrfMetaTags ?> in main layout.

                  这篇关于针对 AJAX 请求的 Yii 2.0 CSRF 验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                  How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                  htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                  Joomla include database functions(Joomla 包含数据库功能)
                  nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                  Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)

                    <tbody id='0szJB'></tbody>

                    • <bdo id='0szJB'></bdo><ul id='0szJB'></ul>
                      • <legend id='0szJB'><style id='0szJB'><dir id='0szJB'><q id='0szJB'></q></dir></style></legend>

                        <tfoot id='0szJB'></tfoot>
                        <i id='0szJB'><tr id='0szJB'><dt id='0szJB'><q id='0szJB'><span id='0szJB'><b id='0szJB'><form id='0szJB'><ins id='0szJB'></ins><ul id='0szJB'></ul><sub id='0szJB'></sub></form><legend id='0szJB'></legend><bdo id='0szJB'><pre id='0szJB'><center id='0szJB'></center></pre></bdo></b><th id='0szJB'></th></span></q></dt></tr></i><div id='0szJB'><tfoot id='0szJB'></tfoot><dl id='0szJB'><fieldset id='0szJB'></fieldset></dl></div>

                          <small id='0szJB'></small><noframes id='0szJB'>