xhui_cool 发表于 2009-1-14 17:46:59

想修改index.php 做一些 权限管理

既然可以将所有网页都重定向到index.php, 那完全可以在index.php里做一些修改,来管理权限

那怎样在index.php里得到 重定向到的地址呢?
我查了下$_SERVER里有如下参数:
'REDIRECT_URL' => string '/admin/login_out' (length=16)
'REQUEST_METHOD' => string 'GET' (length=3)
'QUERY_STRING' => string '' (length=0)
'REQUEST_URI' => string '/admin/login_out' (length=16)
'SCRIPT_NAME' => string '/index.php' (length=10)
'PATH_INFO' => string '/admin/login_out' (length=16)
'PATH_TRANSLATED' => string 'redirect:\index.php\admin\login_out\login_out' (length=45)
'PHP_SELF' => string '/index.php/admin/login_out' (length=26)
'REQUEST_TIME' => int 1231925960

将所有重定向到以 '/admin'开头的地址 都进行 $_SESSION检查,不存在登陆信息的跳转到login.php

这样做安全吗?

该怎么修改法?

trynews 发表于 2009-1-14 23:08:09

我是建钩子来处理,使用post_controller_constructor

Hex 发表于 2009-1-15 00:09:04

修改 index.php 可是坚决坚决不推荐的。
权限处理完全可以用其它方式自动的处理。

xhui_cool 发表于 2009-1-15 09:30:21

。。这么坚决,好吧,我还是用那个复杂的套件吧

PS: 我本以为 我的系统 角色只有一个——admin,修改index.php 实现起来不是最简单的方法么

我对钩子不是很了解,是不是相当于 对某些特定的操作 做一些 特殊的 处理,不管是执行前还是执行后

xhui_cool 发表于 2009-1-15 09:52:23

而且最好是在一个地方处理,没有必要为每一个controller 都写重复的代码

Hex 发表于 2009-1-15 10:22:45

不用为每一个控制器都写同样的代码,你可以做一个 MY_Controller。

huanghuibin 发表于 2009-1-15 11:56:52

MY_Controller.phpclass Public_Controller extends Controller {      function Public_Controller() {                parent::Controller();                //load other stuff                $this->load->library('session'); //载入KNDB session 用户类                $this->load->library('auth'); //载入用户类                $this->load->library('validation' ); //载入验证类                                                $this->load->helper(array('form', 'url' ) );//载入多个辅助函数(用数组的方式)                $this->data->user = $this->auth->get_user($this->session->userdata('user_id'));      }}// Controllers accessible only by logged in usersclass Auth_Controller extends Public_Controller {      function Auth_Controller() {                parent:ublic_Controller();                if ($this->data->user === FALSE) {                        header('Location: '.$this->config->item('base_url').'admin.php/login');                } else {                        return;                }      }}

[ 本帖最后由 huanghuibin 于 2009-1-15 11:58 编辑 ]

xhui_cool 发表于 2009-1-15 12:37:33

。。。在构造函数里做验证
页: [1]
查看完整版本: 想修改index.php 做一些 权限管理