防止在Codeigniter中显示默认的CSRF错误页面

Lui*_*tin 5 php codeigniter csrf

当CSRF令牌过期时,我不喜欢CI在默认情况下的行为方式.例如,当用户长时间显示登录表单并最终提交时,会出现带有错误消息的丑陋空白页面.

我想办法绕过这个,有人告诉我扩展Security类,并覆盖它的csrf_show_error()方法,如下所示:

class MY_Security extends CI_Security {


    public function __construct()
    {
        parent::__construct();

    }

    public function csrf_show_error()
    {
        // comment out the default action
        // show_error('The action you have requested is not allowed.');

        // add redirect actions here
        // I'd like to use some helper function here like redirect()

    }

} 
Run Code Online (Sandbox Code Playgroud)

问题是我不能,或者我不知道如何从这里访问库和帮助程序,以便执行重定向.我不能在这里使用get_instance()函数,因为我收到错误.那么,我还能做些什么呢?或者还有其他更好的选择来阻止显示此错误页面吗?

SLD*_*SLD 3

像这样的核心类CI_Security是在帮助程序和库之前实例化的 - 无法像 CI 应用程序中的其他地方一样使用这些函数。

您必须使用本机 PHP 函数来复制类中的功能,header()如果您只是想重定向到更漂亮的错误页面,那么这并不是什么困难。