繁体   English   中英

CSRF保护Codeigniter

[英]CSRF protection Codeigniter

我可以将 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'];?>" />

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM