【问题标题】:ERROR While enabling CSRF protection TRUE in codeigniter错误在codeigniter中启用CSRF保护时为TRUE
【发布时间】:2017-07-05 11:57:26
【问题描述】:

我的应用程序中有一个表单,出于安全原因,我需要在我的config.php 中添加csrf_protection = TRUE。但是在添加这个之后,我的表单无法提交并向我显示这样的错误。

An Error Was Encountered
The action you have requested is not allowed.

谁能告诉我,如何解决这个问题?

下面是我的 config.php 中的 CSRF 代码

$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();

【问题讨论】:

  • 您的表单中有 CSRF 令牌吗?如果您使用 CI 的 form_open(),它会自动添加它。否则,您可以使用<input type="hidden" name="<?=$csrf['name'];?>" value="<?=$csrf['hash'];?>" /> 手动添加它。 See here.

标签: php codeigniter


【解决方案1】:

如果您打开 CSRF,请确保您使用 form_open 函数打开表单标签,否则您将看到您收到的错误。

以下是此信息的相关链接 -
https://www.codeigniter.com/user_guide/libraries/security.html
Codeigniter CSRF - how does it work
CodeIgniter use CSRF protection only in some pages

【讨论】:

    猜你喜欢
    • 2011-10-23
    • 2023-03-08
    • 2012-09-27
    • 1970-01-01
    • 2015-02-23
    • 2021-10-06
    • 2013-09-20
    • 2012-02-03
    • 2015-04-26
    相关资源
    最近更新 更多