samedi 9 février 2019

How to negate a php if or statement

In one of my websites I am using the following if statement:

if (isAdmin() || (isSupporter() && hasRight("XXX")) {
    echo "<a href='/page'>Menu</a>";
}

This statement is used to determine whether a user can see the link within the main navigation. It will be true of the user is either an admin or a supporter with the given right.

I am now trying to negate this statement in order to prevent users accessing the page the link leads to. Meaning I am trying to find an if statement that will return false if the user is neither an admin nor a supporter with the given right. So far I used the following statement:

if (!isAdmin() || !isSupporter() || !hasRight("XXX")) {
    die();
}

The problem with this statement is, that only users who are admins, supporters and have the given right would be able to access the page. So my question is, is there a way to negate the first statement so that the page will be accessable by either admins OR supporters with the right? Thanks

Aucun commentaire:

Enregistrer un commentaire