doushua7737 2015-06-25 16:34
浏览 42
已采纳

禁止的IP在CodeIgniter之前检查其他任何内容

I have a table with IP/DNS data for banned visitors. I want this check to be done before anything else, but after the model for banned IPs is loaded.

What is the best place to add this code and make it run every time a page is accessed, taking into account that it should load a view for the 403 error to be displayed for banned visitors?

The banned visitors model is loaded globally (specified in autoload.php). Now, I only need to make the function that verifies if the visitor is banned global. Can this be done using hooks? What do you recommend?

  • 写回答

1条回答 默认 最新

  • duanjue6575 2015-06-25 17:17
    关注

    create in the application/core folder a controller named MY_Controller.

    The Controller should look like

    class MY_Controller extends CI_Controller
    {
        public function __construct()
        {
            $this->bannedIpAdresses();
        }
    
        private function bannedIpAdresses()
        {
            $this->load->model("BannedIps_Model");
    
            if ($this->BannedIps_Model->isIpBanned())
            {
                $this->load->view("restricted");
                die();
            }
    
        }
    }
    

    and every other Controller like the welcome Controller should look like

    class Welcome extends MY_Controller {
    
        public function __construct()
        {
            parent::__construct();
        }
    
        public function index()
        {
            $this->load->view('welcome_message');
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害