【问题标题】:CSRF protection CodeigniterCSRF 保护 Codeigniter
【发布时间】:2021-03-14 01:44:57
【问题描述】:

我可以将 CSRF 保护添加到仅在一个页面中的单个表单吗?

如果我在配置文件中创建$config['csrf_protection'] = TRUE;,则它在应用程序中全局适用,但我不想全局使用。

有什么办法可以实现吗?

我搜索了,没有找到任何解决方案。

我试过了

$config['csrf_protection'] = FALSE;

$csrf = array(
        'name' => $this->security->get_csrf_token_name(),
        'hash' => $this->security->get_csrf_hash()
);

<input type="hidden" name="<?=$csrf['name'];?>" value="<?=$csrf['hash'];?>" />

【问题讨论】:

标签: php codeigniter


【解决方案1】:

我之前使用 REQUEST_URI 做过类似的事情,配置文件中的以下条件可以解决问题:

if (stripos($_SERVER["REQUEST_URI"],'/<path_for_which_you_want_enable_CSRF>/') === TRUE) 
{
    $config['csrf_protection']  = TRUE;
} else
{ 
    $config['csrf_protection']  = FALSE; 
}

【讨论】:

    猜你喜欢
    • 2013-09-20
    • 2012-02-03
    • 2011-10-23
    • 2015-08-11
    • 2017-06-14
    • 2023-03-08
    • 2013-02-13
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多