If && not true && not true && true true true

I check if the user variables $_SESSION are populated, and if the login is correct. This is my code:

 if(!empty($_SESSION['user'])&&!empty($_SESSION['pwd'])&&!verifyLogin($_SESSION['user'],$_SESSION['pwd'])){ 

$_SESSION['user'] is the username, $_SESSION['pwd'] is the password, verifyLogin() is my function to verify user login.

Why does my if statement return true even if $_SESSION['user/pwd'] empty? Shouldn't I go back?

Even if I do this:

 if(!empty($_SESSION['user'])&&!empty($_SESSION['pwd'])&&verifyLogin($_SESSION['user'],$_SESSION['pwd'])==false){ 

I still get the same result.

What am I doing wrong?

+4
source share
1 answer

Change your check to use isset via empty . empty will return true from it empty, but also if it is not installed. Check out this post about the difference .

 if (isset(_usr_) && !empty(_usr_) // exists and isn't empty && isset(_pwd_) && !empty(_pwd_) && verifyLogin(_usr_, _pwd_)){ } 

From the empty() manual:

Returns FALSE if var exists and has a non-empty non-zero value . Otherwise, returns TRUE.

i.e. will not be returned TRUE .

+5
source

All Articles