核心代码:
// 检测用户权限权限 public function admin_priv($action){ $action_list = session('user.action_list'); if($action_list == 'all'){ return true; } if(strpos($action_list,$action) === false){ $this->error('权限不够','',1); } }
需要权限限制的页面
// 检测权限 $this->admin_priv('goods_dele');
注意$action_list格式:role_index,role_add,role_edit,goods_index,goods_add,goods_edit,goods_dele,category_index,category_add,category_edit,category_dele,brand_index,brand_add,brand_edit,brand_dele
管理权$action_list是:all
把$action_list放到 session里面
ecshop权限验证
function admin_priv($priv_str, $msg_type = '' , $msg_output = true) { global $_LANG; if ($_SESSION['action_list'] == 'all') { return true; } if (strpos(',' . $_SESSION['action_list'] . ',', ',' . $priv_str . ',') === false) { $link[] = array('text' => $_LANG['go_back'], 'href' => 'javascript:history.back(-1)'); if ( $msg_output) { sys_msg($_LANG['priv_error'], 0, $link); } return false; } else { return true; } }