php权限

function authority($auth)
{
    // pre($_SESSION);
    // pre(Session::get('role'));
    // $role_arr=explode(',', $_SESSION['role']);
    $role_arr = Session::get('role');
    if (!in_array($auth, $role_arr)) {
        if (!in_array('超级管理员', $role_arr)) {
            echo '<h2>没有权限!!你需要【' . $auth. '】的权限</h2>';
            die;
        }
    }
}

/**
 * 权限认证函数,传字符传,一次认证一个权限
 */
function authority_view($quanxian)
{
    // p($_SESSION);die;
    // $role_arr=explode(',', $_SESSION['role']);
    $role_arr = Session::get('role') == null ? $this->redirect('login/index') : Session::get('role');

    if (!in_array($quanxian, $role_arr)) {
        if (in_array('超级管理员', $role_arr)) {
            // echo '<h2>没有权限!!你需要【'.$quanxian.'】的权限</h2>';
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }
}
posted @ 2020-03-17 10:33  xiondun  阅读(125)  评论(0编辑  收藏  举报