mercredi 11 novembre 2015

PHP - If statement always evaluating as true?

So I can't get my head around this if statement.

What I am trying to do is get the person logged in from $_SESSION["user_name"] and if it matches one of two possible "admin" users, to give extra functionality. But it's always firing true.

For the example I'm going to have three users: Emma, John and Robert. Emma and John should be allowed the extra "admin functionality", but Robert is not allowed it. So...

My statement is:

if ($_SESSION["user_name"] === "emma" or "john"){
//give extra functionality as well as basic functionality
} else {
//give just basic functionality

But this is always firing true, so when I log in as my test account with the username Robert, he is also getting the extra functionality.

I've tried changing the quotation marks " of $_SESSION to apostrophes ', and also tried changing the operator from === to ==. I even tried = but found the hard way that this was setting my $_SESSION variable to "emma".

What am I doing wrong because I just can't seem to get my head around it?

If it's worth noting, this if statement is contained in a parent if statement that uses colons : and endif rather than brackets {}. The parent if statement is purely there to decide on what functionality to output based a column returned being empty or a user's name in there.

Aucun commentaire:

Enregistrer un commentaire