Hi there,
I am currently learning about sessions in PHP, and I am having a problem with $_SESSION in an IF statement.
I am trying to create a login page that will set $_SESSION[‘login’] from 0 to:
– 1 if successful
– 2 if not successful (i.e, wrong password)
[CODE]if(…username and password are valid…) {
$_SESSION[‘login’] = 1;
}
else {
$_SESSION[‘login’] = 2;
}
}
$loginstatus = $_SESSION[‘login’];
if( $loginstatus == 1 ) {
header(“Location: content.php?cid=100”);
}
else {
header(“Location: login.php”);
}
Either it is 1 or 2, the page directs to content.php (which is wrong.. if it is 2, it is supposed to go to login.php). If I change
[CODE]$_SESSION[‘login’] = 2;
to:
[CODE]$_SESSION[‘login’] = 0
and I enter incorrect username/password, login.php loads up. So, long story short, it seems like the comparison only works for either 0 or 1. Does anyone know why?