I’m checking if user $_SESSION variables 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 username, $_SESSION['pwd'] is password, verifyLogin() is my function for validating user’s login.
Why does my if statement returns true even if $_SESSION['user/pwd'] are empty? Shouldn’t I get back false?
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?
Change your check to use
issetoverempty.emptywill return true of it’s empty, but also if it’s not set. Check out this post about the difference.From the manual of
empty():i.e. not set will return
TRUE.