【问题标题】:CSRF Codeigniter 3 ValidationCSRF Codeigniter 3 验证
【发布时间】:2018-01-21 05:33:12
【问题描述】:

我一直在阅读有关 codeigniter 中 crsf 保护的内容,但我似乎找不到一个像样的教程来说明在配置文件中启用 csrf 后如何继续操作。

我有一个由控制器函数 users/create 生成的表单,该表单提交给另一个函数 users/submit_new

我使用了表单助手类,以便自动生成 crsf 字段。

我在提交功能上有这个验证功能:

if ($this->input->post(get_csrf_token_name()) == get_csrf_hash()) {
$this->users_model->create(); }

但我得到的只是 action not allowed 错误。 验证 csrf 的正确方法是什么?还是我做错了什么?

【问题讨论】:

    标签: php codeigniter csrf codeigniter-3 csrf-protection


    【解决方案1】:

    如果您按照用户指南中提到的方式使用 CodeIgniter CSRF,请设置:

    $config['csrf_protection'] = TRUE; // this in application/config/config.php
    

    而且您还使用表单助手来生成表单打开标记,那么您不需要检查令牌并按照您的方式进行哈希处理。 CodeIgniter 会为您完成这项工作。

    阅读文档:https://www.codeigniter.com/user_guide/libraries/security.html#cross-site-request-forgery-csrf

    如果仍有问题,请查看相关问题:

    codeigniter CSRF error: "The action you have requested is not allowed."

    Action you have requested is not allowed error

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      • 2011-10-15
      • 2016-01-23
      • 2016-03-03
      • 2011-09-28
      • 2016-09-22
      相关资源
      最近更新 更多