Prevent untraced users from accessing pages

1

I have a class called "account" and its methods are the pages that the logged-in user can access, eg

Class account {

function info (){
//bla bla
}
function post () {
// bla bla
}

}

and for each method that the user is going to access, I have to make a conditional to check if the session is active, eg:

if($userLogged){
//deixar acessar
} else {
//redireciona
}

Is there any way to do a single check for all methods? something like a construct, for whatever method that was instantiated the verification would already be done and would try to give access or redirect the user.

UPDATE:

Is it safe to do a simple construct for this? ex:

function __construct() {

        if (!$userLogged)
            die('blabla');
    }
    
asked by anonymous 17.09.2016 / 22:39

1 answer

0

Try to use the magic method: __call which is activated whenever you try to access some class function.

    
18.09.2016 / 01:09