我只想在几个控制器中打开csrf保护,所以我有
function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->library('tank_auth');
$this->load->helper(array('form', 'url'));
$this->load->model('user_model', '', true);
$this->config->set_item('csrf_protection', TRUE);
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用,尽管当我在页面上执行var_dump($ this-> config)时,它表明csrf_protection为TRUE,但未设置cookie,并且窗体具有一个没有值的隐藏字段
<input type="hidden" name="ci_csrf_token" value="" />
Csrf令牌名称和cookie名称都已设置,使用form_open()调用表单。
任何帮助将非常感激。
更新:由于安全类构造中的这一行,因此从2.1.1版本开始这是不可能的if (config_item('csrf_protection') === TRUE) {
安全类在控制器之前初始化,因此自然而然地改变了控制器中的配置项不会影响它。