【发布时间】:2017-12-28 22:33:17
【问题描述】:
我的 CI 网站有 csrf 保护。
$config['csrf_protection'] = TRUE;
所以,当我通过刷新重新提交表单时,我收到以下错误。
您请求的操作不被允许
我希望它返回到最后一页,而不是显示此消息。
所以,我尝试通过扩展 CI_Security 文件来覆盖 csrf_show_error() 方法。
这是我的课程,位于 application/core/My_Security.php
class MY_Security extends CI_Security {
public function __construct()
{
parent::__construct();
$this->load->library('user_agent');
}
public function csrf_show_error()
{
// show_error('The action you have requested is not allowed.'); // default code
// force page "refresh" - redirect back to itself
// a page refresh restores the CSRF cookie
if ($this->agent->is_referral())
{
redirect(site_url());
} else {
redirect($_SERVER['HTTP_REFERER']);
}
}
}
我收到以下错误
在非对象上调用成员函数 library()
【问题讨论】:
标签: codeigniter csrf-protection