将我的整个php网站包装在isLoggedIn()中并且hasPermission()被认为是糟糕的编码实践


Is wrapping my whole php website within isLoggedIn() and hasPermission() considered bad coding practice?

所以我正在编写一个Web应用程序。每个人都可以注册一个帐户,但是未经管理员批准,将无法访问该网站。

我是这样试过的:

if($user->isLoggedIn()) {
        if($user->hasPermission('user')) {
                //my whole website
        }
echo "Admin hasn't approved your account yet;
}

isLoggedIn() 检查用户是否登录,hasPermission() 检查保存在我的数据库中的 json 字符串中的用户权限。

将我的整个网站放在这两个 if 语句中是否被认为是糟糕的编码实践,是否有更好的方法来做到这一点,或者我的方法很好?

class Foo { 
    function __construct() { 
        //do ur permission check here 
    } 

    function some_custom_func() { 
        //do ur action here
    } 
} 

自定义函数不会在没有先执行构造函数的情况下执行!