我正在尝试在我的 CodeIgniter 3 应用程序中启用 CSRF 保护。但是,当我尝试在我的视图文件中使用
get_csrf_hash()
函数时,它没有返回值。我该如何解决这个问题?
在CodeIgniter 3中使用
$this->security->get_csrf_token_name()
时,只会生成CSRF token字段的name属性值,而使用$this->security->get_csrf_hash()
不会生成value属性。
要在您的 CodeIgniter 3 应用程序中启用 CSRF 保护,您需要执行以下操作:
打开位于
config.php
目录中的application/config/
文件。
将
$config['csrf_protection']
设置为TRUE以启用CSRF保护:
$config['csrf_protection'] = TRUE;
保存
config.php
文件。
注意 您需要在控制器中加载表单助手和安全助手,然后才能分别使用
form_hidden()
函数以及 get_csrf_token_name()
和 get_csrf_hash()
函数:
$this->load->helper('form');
$this->load->helper('security');