I dont't understand this. If $_GET['action'] is set and action is not "login" or not "messages" I want to doAction().
My non working code:
if ( isset($_GET['action']) && ($_GET['action'] !== "login" || $_GET['action'] !== "messages") ) {
doAction();
}
If I remove the || it works.
if ( isset($_GET['action']) && ($_GET['action'] !== "login") ) {
doAction();
}
Any hints?
Okay, let's check execution of your
ifstatement:isset($_GET['action'])true and$_GET['action'] !== "login"is trueAs php has lazy execution (
trueandtrueistrue) the comparison stopped and yourdoActionexecutes, fine, just what we need.suppose, action is login then
isset($_GET['action'])true and$_GET['action'] !== "login"is false and$_GET['action'] !== "messages"is true (as login is definitely not messages). So (trueand (falseortrue)) istrue!finally suppose, action is messages then
isset($_GET['action'])true and$_GET['action'] !== "login"is true. Considering lazy execution yourdoActionruns again.Okay! Looks like that
doActionwill work always!Fix for the problem is using
and (&&)instead ofor (||)in youif